1
0
mirror of https://github.com/kalmarek/PropertyT.jl.git synced 2024-11-23 08:15:29 +01:00

Make algebra elts work with SparseVectors

This commit is contained in:
kalmar 2017-02-11 13:26:30 +01:00
parent e69f5d13b6
commit 9fd48445eb

View File

@ -8,11 +8,11 @@ export GroupAlgebraElement
immutable GroupAlgebraElement{T<:Number} immutable GroupAlgebraElement{T<:Number}
coefficients::Vector{T} coefficients::AbstractVector{T}
product_matrix::Array{Int,2} product_matrix::Array{Int,2}
# basis::Array{Any,1} # basis::Array{Any,1}
function GroupAlgebraElement(coefficients::Vector{T}, function GroupAlgebraElement(coefficients::AbstractVector,
product_matrix::Array{Int,2}) product_matrix::Array{Int,2})
size(product_matrix, 1) == size(product_matrix, 2) || size(product_matrix, 1) == size(product_matrix, 2) ||
@ -22,10 +22,10 @@ immutable GroupAlgebraElement{T<:Number}
end end
# GroupAlgebraElement(c,pm,b) = GroupAlgebraElement(c,pm) # GroupAlgebraElement(c,pm,b) = GroupAlgebraElement(c,pm)
GroupAlgebraElement{T}(c::Vector{T},pm) = GroupAlgebraElement{T}(c,pm) GroupAlgebraElement{T}(c::AbstractVector{T},pm) = GroupAlgebraElement{T}(c,pm)
convert{T<:Number}(::Type{T}, X::GroupAlgebraElement) = convert{T<:Number}(::Type{T}, X::GroupAlgebraElement) =
GroupAlgebraElement(convert(Vector{T}, X.coefficients), X.product_matrix) GroupAlgebraElement(convert(AbstractVector{T}, X.coefficients), X.product_matrix)
show{T}(io::IO, X::GroupAlgebraElement{T}) = print(io, show{T}(io::IO, X::GroupAlgebraElement{T}) = print(io,
"Element of Group Algebra over $T of length $(length(X)):\n $(X.coefficients)") "Element of Group Algebra over $T of length $(length(X)):\n $(X.coefficients)")
@ -59,7 +59,7 @@ end
(-)(X::GroupAlgebraElement) = GroupAlgebraElement(-X.coefficients, X.product_matrix) (-)(X::GroupAlgebraElement) = GroupAlgebraElement(-X.coefficients, X.product_matrix)
(-)(X::GroupAlgebraElement, Y::GroupAlgebraElement) = add(X,-Y) (-)(X::GroupAlgebraElement, Y::GroupAlgebraElement) = add(X,-Y)
function algebra_multiplication{T<:Number}(X::Vector{T}, Y::Vector{T}, pm::Array{Int,2}) function algebra_multiplication{T<:Number}(X::AbstractVector{T}, Y::AbstractVector{T}, pm::Array{Int,2})
result = zeros(X) result = zeros(X)
for (i,x) in enumerate(X) for (i,x) in enumerate(X)
if x != 0 if x != 0