mirror of
https://github.com/kalmarek/GroupRings.jl.git
synced 2024-12-28 18:50:29 +01:00
preserve storage type of X.coeffs
This commit is contained in:
parent
075c6151a6
commit
c7115c689e
@ -114,10 +114,17 @@ end
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
# sparse storage:
|
||||
|
||||
zero(RG::GroupRing, T::Type=Int) = RG(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)
|
||||
|
||||
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)
|
||||
elt = RG(T)
|
||||
elt[RG.group()] = i
|
||||
@ -130,24 +137,12 @@ function (RG::GroupRing{R})(i::Int, T::Type=Int) where {R<:Ring}
|
||||
return elt
|
||||
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)
|
||||
result = RG(T)
|
||||
result[RG.group(g)] = one(T)
|
||||
return result
|
||||
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}
|
||||
res = RG(S)
|
||||
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
|
||||
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)
|
||||
RG == parent(X) || throw("Can not coerce!")
|
||||
return RG(X.coeffs)
|
||||
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")
|
||||
result = RG(eltype(X.coeffs))
|
||||
T = typeof(X.coeffs)
|
||||
result.coeffs = T(result.coeffs)
|
||||
for g in parent(X).basis
|
||||
result[emb(g)] = X[g]
|
||||
res = RG(zeros(X.coeffs))
|
||||
|
||||
for g in RG.basis
|
||||
res[f(g)] = X[g]
|
||||
end
|
||||
return result
|
||||
return res
|
||||
end
|
||||
|
||||
###############################################################################
|
||||
|
Loading…
Reference in New Issue
Block a user