1
0
mirror of https://github.com/kalmarek/GroupRings.jl.git synced 2024-10-15 07:50:35 +02:00

preserve storage type of X.coeffs

This commit is contained in:
kalmarek 2018-08-14 19:28:24 +02:00
parent 075c6151a6
commit c7115c689e

View File

@ -114,10 +114,17 @@ end
# #
############################################################################### ###############################################################################
# sparse storage:
zero(RG::GroupRing, T::Type=Int) = RG(T) zero(RG::GroupRing, T::Type=Int) = RG(T)
one(RG::GroupRing, T::Type=Int) = RG(RG.group(), T) one(RG::GroupRing, T::Type=Int) = RG(RG.group(), T)
one(RG::GroupRing{R}, T::Type=Int) where {R<:Ring} = RG(one(RG.group()), T) one(RG::GroupRing{R}, T::Type=Int) where {R<:Ring} = RG(one(RG.group()), T)
function (RG::GroupRing)(T::Type=Int)
isdefined(RG, :basis) || throw("Can not coerce without basis of GroupRing")
return GroupRingElem(spzeros(T,length(RG.basis)), RG)
end
function (RG::GroupRing)(i::Int, T::Type=Int) function (RG::GroupRing)(i::Int, T::Type=Int)
elt = RG(T) elt = RG(T)
elt[RG.group()] = i elt[RG.group()] = i
@ -130,24 +137,12 @@ function (RG::GroupRing{R})(i::Int, T::Type=Int) where {R<:Ring}
return elt return elt
end end
function (RG::GroupRing)(T::Type=Int)
isdefined(RG, :basis) || throw("Can not coerce without basis of GroupRing")
return GroupRingElem(spzeros(T,length(RG.basis)), RG)
end
function (RG::GroupRing)(g::GroupElem, T::Type=Int) function (RG::GroupRing)(g::GroupElem, T::Type=Int)
result = RG(T) result = RG(T)
result[RG.group(g)] = one(T) result[RG.group(g)] = one(T)
return result return result
end end
function (RG::GroupRing)(x::AbstractVector{T}) where {T<:Number}
length(x) == length(RG.basis) || throw("Can not coerce to $RG: lengths differ")
result = RG(T)
result.coeffs = x
return result
end
function (RG::GroupRing{Gr,T})(V::Vector{T}, S::Type=Int) where {Gr<:Group, T<:GroupElem} function (RG::GroupRing{Gr,T})(V::Vector{T}, S::Type=Int) where {Gr<:Group, T<:GroupElem}
res = RG(S) res = RG(S)
for g in V for g in V
@ -156,20 +151,26 @@ function (RG::GroupRing{Gr,T})(V::Vector{T}, S::Type=Int) where {Gr<:Group, T<:G
return res return res
end end
# keep storage type
function (RG::GroupRing)(x::AbstractVector{T}) where T
length(x) == length(RG.basis) || throw("Can not coerce to $RG: lengths differ")
return GroupRingElem(x, RG)
end
function (RG::GroupRing)(X::GroupRingElem) function (RG::GroupRing)(X::GroupRingElem)
RG == parent(X) || throw("Can not coerce!") RG == parent(X) || throw("Can not coerce!")
return RG(X.coeffs) return RG(X.coeffs)
end end
function (RG::GroupRing)(X::GroupRingElem, emb::Function) function (RG::GroupRing)(f::Function, X::GroupRingElem)
isdefined(RG, :basis) || throw("Can not coerce without basis of GroupRing") isdefined(RG, :basis) || throw("Can not coerce without basis of GroupRing")
result = RG(eltype(X.coeffs)) res = RG(zeros(X.coeffs))
T = typeof(X.coeffs)
result.coeffs = T(result.coeffs) for g in RG.basis
for g in parent(X).basis res[f(g)] = X[g]
result[emb(g)] = X[g]
end end
return result return res
end end
############################################################################### ###############################################################################