Skip to content
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ julia = "1.10"
LinearAlgebra = "1"
Random = "1"
Reexport = "1"
StatsBase = "0.34"
TensorOperations = "5"
Test = "1"
TestExtras = "0.3.2"
Expand All @@ -27,9 +28,10 @@ Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
TensorOperations = "6aa20fa7-93e2-5fca-9bc0-fbd0db3c71a2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestExtras = "5ed8adda-3752-4e41-b88a-e8b09835ee3a"

[targets]
test = ["Aqua", "JET", "Test", "TestExtras", "TensorOperations", "Random", "Reexport"]
test = ["Aqua", "JET", "Test", "TestExtras", "TensorOperations", "Random", "Reexport", "StatsBase"]
9 changes: 7 additions & 2 deletions src/timereversed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,15 @@ dual(c::TimeReversed{I}) where {I <: Sector} = TimeReversed{I}(dual(c.a))
function ⊗(c1::TimeReversed{I}, c2::TimeReversed{I}) where {I <: Sector}
return SectorSet{TimeReversed{I}}(TimeReversed{I}, c1.a ⊗ c2.a)
end
function Base.IteratorSize(::Type{SectorValues{TimeReversed{I}}}) where {I <: Sector}

# capture product sectors as well
Comment thread
borisdevos marked this conversation as resolved.
Outdated
function Base.IteratorSize(::Type{SectorValues{TimeReversed{I}}}) where {I}
Comment thread
lkdvos marked this conversation as resolved.
return Base.IteratorSize(values(I))
end
function Base.length(::SectorValues{TimeReversed{I}}) where {I <: Sector}
function Base.size(::SectorValues{TimeReversed{I}}) where {I}
return size(values(I))
end
function Base.length(::SectorValues{TimeReversed{I}}) where {I}
return length(values(I))
end
function Base.getindex(::SectorValues{TimeReversed{I}}, i::Int) where {I <: Sector}
Expand Down
12 changes: 11 additions & 1 deletion test/testsuite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ using TestExtras
using TensorKitSectors
using TensorKitSectors: type_repr
using Random
using StatsBase
using Base.Iterators: take, product

const tests = Dict()
Expand Down Expand Up @@ -69,7 +70,16 @@ function test_sector(I::Type)
end
end

smallset(::Type{I}) where {I <: Sector} = take(values(I), 5)
function StatsBase.sample(::SectorValues{I}, size::Int) where {I <: Sector}
Base.IteratorSize(values(I)) === Base.IsInfinite() &&
throw(ArgumentError("Cannot take random sample of infinite sector values."))
return sample(collect(values(I)), size; replace = false) # unique sampling
end
function smallset(::Type{I}, size::Int = 5) where {I <: Sector}
vals = values(I)
Base.IteratorSize(vals) === Base.IsInfinite() && return take(vals, size)
return sample(vals, min(size, length(vals)))
end
Comment thread
borisdevos marked this conversation as resolved.
Outdated
function smallset(::Type{ProductSector{Tuple{I1, I2}}}) where {I1, I2}
iter = product(smallset(I1), smallset(I2))
s = collect(i ⊠ j for (i, j) in iter if dim(i) * dim(j) <= 6)
Expand Down