Skip to content

Commit 5a216bf

Browse files
borisdevoslkdvos
andauthored
Edit smallset to sample in tests (#74)
* edit `smallset` to sample * add compat * sample without relying on StatsBase * Update test/testsuite.jl Co-authored-by: Lukas Devos <ldevos98@gmail.com> * prevent empty smallsets * refactor `randsubseq` and use for deligne products as well * sample with fixed size * use `shuffle` and have it work for infinite sectors + product sectors * code suggestions * deal with comments about comments and remove comments with no comment --------- Co-authored-by: Lukas Devos <ldevos98@gmail.com>
1 parent 21204c4 commit 5a216bf

2 files changed

Lines changed: 10 additions & 12 deletions

File tree

src/timereversed.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,14 @@ dual(c::TimeReversed{I}) where {I <: Sector} = TimeReversed{I}(dual(c.a))
5151
function (c1::TimeReversed{I}, c2::TimeReversed{I}) where {I <: Sector}
5252
return SectorSet{TimeReversed{I}}(TimeReversed{I}, c1.a c2.a)
5353
end
54-
function Base.IteratorSize(::Type{SectorValues{TimeReversed{I}}}) where {I <: Sector}
54+
55+
function Base.IteratorSize(::Type{SectorValues{TimeReversed{I}}}) where {I}
5556
return Base.IteratorSize(values(I))
5657
end
57-
function Base.length(::SectorValues{TimeReversed{I}}) where {I <: Sector}
58+
function Base.size(::SectorValues{TimeReversed{I}}) where {I}
59+
return size(values(I))
60+
end
61+
function Base.length(::SectorValues{TimeReversed{I}}) where {I}
5862
return length(values(I))
5963
end
6064
function Base.getindex(::SectorValues{TimeReversed{I}}, i::Int) where {I <: Sector}

test/testsuite.jl

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,10 @@ function test_sector(I::Type)
6969
end
7070
end
7171

72-
smallset(::Type{I}) where {I <: Sector} = take(values(I), 5)
73-
function smallset(::Type{ProductSector{Tuple{I1, I2}}}) where {I1, I2}
74-
iter = product(smallset(I1), smallset(I2))
75-
s = collect(i j for (i, j) in iter if dim(i) * dim(j) <= 6)
76-
return length(s) > 6 ? rand(s, 6) : s
77-
end
78-
function smallset(::Type{ProductSector{Tuple{I1, I2, I3}}}) where {I1, I2, I3}
79-
iter = product(smallset(I1), smallset(I2), smallset(I3))
80-
s = collect(i j k for (i, j, k) in iter if dim(i) * dim(j) * dim(k) <= 6)
81-
return length(s) > 6 ? rand(s, 6) : s
72+
function smallset(::Type{I}, size::Int = 5, maxdim::Real = 10) where {I <: Sector}
73+
sectors = collect(Iterators.take(values(I), 10 * size))
74+
sectors = shuffle!(filter!(s -> dim(s) < maxdim, sectors))
75+
return resize!(sectors, min(size, length(sectors)))
8276
end
8377

8478
function randsector(::Type{I}) where {I <: Sector}

0 commit comments

Comments
 (0)