Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Dec 7, 2023
1 parent 00c977a commit b728508
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 21 deletions.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ version = "0.2.0"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MutableArithmetics = "d8a4904e-b15c-11e9-3269-09a3773c0cb0"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[compat]
MutableArithmetics = "1"
julia = "1.6"
2 changes: 2 additions & 0 deletions src/StarAlgebras.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ module StarAlgebras
using SparseArrays
import LinearAlgebra

import MutableArithmetics as MA

export StarAlgebra, AlgebraElement
export aug, basis, coeffs, star, supp

Expand Down
2 changes: 1 addition & 1 deletion src/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Base.:^(a::AlgebraElement, p::Integer) = Base.power_by_squaring(a, p)
# mutable API; TODO: replace with MutableArithmetic

function zero!(a::AlgebraElement)
a.coeffs .= zero(eltype(coeffs(a)))
MA.operate!(zero, a.coeffs)
return a
end

Expand Down
1 change: 1 addition & 0 deletions src/bases.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Implements a bijection between basis elements and integers.
abstract type AbstractBasis{T,I} end

Base.eltype(::Type{<:AbstractBasis{T}}) where {T} = T
Base.eltype(b::AbstractBasis) = eltype(typeof(b))
Base.keytype(::Type{<:AbstractBasis{T,I}}) where {T,I} = I
Base.keytype(b::AbstractBasis) = keytype(typeof(b))

Expand Down
27 changes: 26 additions & 1 deletion src/coefficients.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,20 @@ struct SparseCoefficients{
values::Vv
end

function MA.operate!(::typeof(zero), s::SparseCoefficients)
empty!(s.basis_elements)
empty!(s.values)
return s
end

Base.keys(sc::SparseCoefficients) = sc.basis_elements
Base.values(sc::SparseCoefficients) = sc.values

Base.zero(sc::SparseCoefficients) = SparseCoefficients(empty(keys(sc)), empty(values(sc)))

function Base.similar(s::SparseCoefficients, ::Type{T}) where {T}
return SparseCoefficients(similar(s.basis_elements), similar(s.values, T))
end

function unsafe_append!(mc::SparseCoefficients, p::Pair{<:AbstractCoefficients,T}) where {T}
c, val = p
Expand All @@ -67,7 +76,23 @@ function unsafe_append!(mc::SparseCoefficients, p::Pair{<:AbstractCoefficients,T
return mc
end

function fmac!(
res::AlgebraElement{A,T,<:SparseCoefficients},
X::AlgebraElement{A,T,<:SparseCoefficients},
Y::AlgebraElement{A,T,<:SparseCoefficients},
) where {A,T}
x = coeffs(X)
y = coeffs(Y)
for (kx, vx) in zip(x.basis_elements, x.values)
for (ky, vy) in zip(y.basis_elements, y.values)
MA.operate!(MA.add_mul, res, vx * vy, basis(parent(X))[kx], basis(parent(Y))[ky])
end
end
return res
end


function __canonicalize!(res::SparseCoefficients)
@error "in __canonicalize!: Not implemented yet"
@error "in __canonicalize!: Not implemented yet"
return res
end
3 changes: 0 additions & 3 deletions src/mstructures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ struct LazyMStructure{T,B<:AbstractBasis{T}} <: MultiplicativeStructure{T}
basis::B
end

LazyMStructure(basis::AbstractBasis{T}) where {T} =
LazyMStructure{T,typeof(basis)}(basis)

basis(mstr::LazyMStructure) = mstr.basis

function Base.getindex(::LazyMStructure{<:DiracBasis{T}}, x::T, y::T) where {T}
Expand Down
4 changes: 2 additions & 2 deletions src/mtables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ struct MTable{
star_of::V
end

function MTable(basis::DiracBasis{T,I}; size::Tuple{Int,Int}) where {V,K<:Integer}
return MTable(zeros(K, size), _star_of(basis, (x -> x[1] < max(size...))), basis)
function MTable(basis::DiracBasis{T,I}; size::Tuple{Int,Int}) where {T,I<:Integer}
return MTable(zeros(I, size), _star_of(basis, (x -> x[1] < max(size...))), basis)
end

basis(mt::MTable) = mt.basis
Expand Down
19 changes: 11 additions & 8 deletions src/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ function Base.show(io::IO, a::AlgebraElement)
else
print(io, zero(T))
end
elseif hasbasis(A)
nzeros = findall(!iszero, coeffs(a))
for (counter, idx) in enumerate(nzeros)
c, elt = coeffs(a)[idx], basis(A)[idx]
if counter == 1
else #if hasbasis(A)
#nzeros = findall(!iszero, coeffs(a))
first = true
for (idx, value) in zip(keys(coeffs(a)), values(coeffs(a)))
#for (counter, idx) in enumerate(nzeros)
c, elt = value, basis(A)[idx]
if first
_coeff_elt_print(io, c, elt)
first = false
else
if __prints_with_minus(c)
print(io, ' ')
Expand All @@ -40,9 +43,9 @@ function Base.show(io::IO, a::AlgebraElement)
_coeff_elt_print(io, c, elt)
end
end
else
println(io, "algebra element without defined basis")
show(io, MIME("text/plain"), a.coeffs)
# else
# println(io, "algebra element without defined basis")
# show(io, MIME("text/plain"), a.coeffs)
end
end

Expand Down
12 changes: 6 additions & 6 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ struct AlgebraElement{A,T,V}
coeffs::V
parent::A

function AlgebraElement(coeffs::AbstractVector, A::AbstractStarAlgebra)
if hasbasis(A)
@assert length(coeffs) == length(basis(A))
end
return new{typeof(A),eltype(coeffs),typeof(coeffs)}(coeffs, A)
function AlgebraElement(coeffs, A::AbstractStarAlgebra)
#if hasbasis(A)
# @assert length(coeffs) == length(basis(A))
#end
return new{typeof(A),valtype(coeffs),typeof(coeffs)}(coeffs, A)
end
end

coeffs(a::AlgebraElement) = a.coeffs
Base.parent(a::AlgebraElement) = a.parent
Base.eltype(a::AlgebraElement) = eltype(coeffs(a))
Base.eltype(a::AlgebraElement) = valtype(coeffs(a))

### constructing elements
Base.zero(A::AbstractStarAlgebra) = zero(Int, A)
Expand Down

0 comments on commit b728508

Please sign in to comment.