From 7ba59d6508123af9002a6e6b004bbe90e321f970 Mon Sep 17 00:00:00 2001 From: kalmar Date: Mon, 5 Jun 2017 21:36:31 +0200 Subject: [PATCH 1/3] safer coercion of GroupRingElem to GroupRing --- src/GroupRings.jl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/GroupRings.jl b/src/GroupRings.jl index cc2faab..31bbff1 100644 --- a/src/GroupRings.jl +++ b/src/GroupRings.jl @@ -131,7 +131,10 @@ function (RG::GroupRing)(x::AbstractVector) return result end -(RG::GroupRing)(X::GroupRingElem) = RG(X.coeffs) +function (RG::GroupRing)(X::GroupRingElem) + RG == parent(X) || throw("Can not coerce!") + return RG(X.coeffs) +end ############################################################################### # From b2231c44e61f527171b795de59ae892bd31f9722 Mon Sep 17 00:00:00 2001 From: kalmar Date: Mon, 5 Jun 2017 21:37:11 +0200 Subject: [PATCH 2/3] coercion to GroupRing via specified function on underlying groups --- src/GroupRings.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/GroupRings.jl b/src/GroupRings.jl index 31bbff1..c8ffbc2 100644 --- a/src/GroupRings.jl +++ b/src/GroupRings.jl @@ -136,6 +136,14 @@ function (RG::GroupRing)(X::GroupRingElem) return RG(X.coeffs) end +function (RG::GroupRing)(X::GroupRingElem, emb::Function) + result = RG(eltype(X.coeffs)) + for g in parent(X).basis + result[emb(g)] = X[g] + end + return result +end + ############################################################################### # # Basic manipulation From 1e7537206826ce950a6ef840b3f698cff6facd95 Mon Sep 17 00:00:00 2001 From: kalmar Date: Mon, 5 Jun 2017 21:38:03 +0200 Subject: [PATCH 3/3] in setindex! perform coercion only when necessary --- src/GroupRings.jl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/GroupRings.jl b/src/GroupRings.jl index c8ffbc2..f02d6cf 100644 --- a/src/GroupRings.jl +++ b/src/GroupRings.jl @@ -173,8 +173,11 @@ end function setindex!(X::GroupRingElem, value, g::GroupElem) RG = parent(X) typeof(g) == elem_type(RG.group) || throw("$g is not an element of $(RG.group)") - g = (RG.group)(g) - X.coeffs[RG.basis_dict[g]] = value + if !(g in keys(RG.basis_dict)) + g = (RG.group)(g) + else + X.coeffs[RG.basis_dict[g]] = value + end end eltype(X::GroupRingElem) = eltype(X.coeffs)