Skip to content

Commit

Permalink
allow no cache in FixedBasis
Browse files Browse the repository at this point in the history
  • Loading branch information
kalmarek committed Apr 14, 2024
1 parent f22b273 commit ece736f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
10 changes: 5 additions & 5 deletions src/bases_fixed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ mutable struct FixedBasis{T,I,V<:AbstractVector{T},M<:MTable{T,I}} <:
table::M
end

function FixedBasis(basis::AbstractBasis; n::Integer, mt::Integer)
@assert 0 < mt n
function FixedBasis(basis::AbstractBasis; n::Integer, mt::Integer = 0)
@assert 0 mt n
elts = Iterators.take(basis, n)
return FixedBasis(elts, mstructure(basis), (mt, mt))
return FixedBasis(collect(elts), mstructure(basis), (mt, mt))
end

function FixedBasis(
elts::AbstractVector,
mstr::MultiplicativeStructure,
dims::NTuple{2,I},
) where {I<:Integer}
@assert 0 < dims[1] length(elts)
@assert 0 < dims[2] length(elts)
@assert 0 dims[1] length(elts)
@assert 0 dims[2] length(elts)
@assert !(eltype(elts) <: Integer)
return FixedBasis(elts, MTable(elts, mstr, dims))
end
Expand Down
19 changes: 11 additions & 8 deletions src/mtables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,18 @@ Base.@propagate_inbounds __iscomputed(mt::MTable, i, j) =
isassigned(mt.table, i, j) && !iszero(mt.table[i, j])

Base.@propagate_inbounds function (mt::MTable)(i::Integer, j::Integer)
@boundscheck checkbounds(mt.table, abs(i), abs(j))
@inbounds begin
i = __absindex(mt, i)
j = __absindex(mt, j)

if !__iscomputed(mt, i, j)
complete!(mt, i, j)
i = __absindex(mt, i)
j = __absindex(mt, j)
if checkbounds(Bool, mt.table, i, j)
@inbounds begin
if !__iscomputed(mt, i, j)
complete!(mt, i, j)
end
return mt.table[i, j]
end
return mt.table[i, j]
else
g, h = mt[i], mt[j]
return mt.mstr(g, h)
end
end
Base.@propagate_inbounds function (mt::MTable{T})(x::T, y::T) where {T}
Expand Down
10 changes: 3 additions & 7 deletions test/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,8 @@ end
RG = StarAlgebra(A★, B)
@test basis(RG) === B

words = collect(Iterators.take(A★, nwords(A★, 0, 8)))
l = nwords(A★, 4)

@assert length(words[l]) == 4 && length(words[l+1]) == 5

fB = SA.FixedBasis(words, SA.DiracMStructure(*), UInt32.((l, l)))
# no caching
fB = SA.FixedBasis(basis(RG); n = nwords(A★, 0, 8), mt = 0)
@test fB.table.elts === fB.elts

fRG = StarAlgebra(A★, fB)
Expand Down Expand Up @@ -279,7 +275,7 @@ end
end

@testset "FixedBasis caching && allocations" begin
fB = SA.FixedBasis(words, SA.DiracMStructure(*), UInt32.((l, l)))
fB = SA.FixedBasis(B; n = nwords(A★, 8), mt = UInt32(nwords(A★, 4)))
fRG = StarAlgebra(A★, fB)

k = size(SA.mstructure(basis(fRG)), 1)
Expand Down

0 comments on commit ece736f

Please sign in to comment.