From 43d78c97f840649f28d700a12f225c1d662c48bc Mon Sep 17 00:00:00 2001 From: kalmar Date: Mon, 5 Jun 2017 23:50:15 +0200 Subject: [PATCH 1/3] parametrise GroupRing by Group and GroupElem as suggested by thofma --- src/GroupRings.jl | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/GroupRings.jl b/src/GroupRings.jl index cc2faab..8073cd4 100644 --- a/src/GroupRings.jl +++ b/src/GroupRings.jl @@ -11,13 +11,13 @@ import Base: convert, show, hash, ==, +, -, *, //, /, length, norm, rationalize, # ############################################################################### -type GroupRing <: Ring - group::Group - basis::Vector{GroupElem} - basis_dict::Dict{GroupElem, Int} +type GroupRing{Gr<:Group, T<:GroupElem} <: Ring + group::Gr + basis::Vector{T} + basis_dict::Dict{T, Int} pm::Array{Int,2} - function GroupRing(G::Group; initialise=true) + function GroupRing(G::Gr; initialise=true) A = new(G) if initialise complete(A) @@ -25,11 +25,15 @@ type GroupRing <: Ring return A end - function GroupRing(G::Group, basis, basis_dict, pm::Array{Int,2}) + function GroupRing(G::Gr, basis::Vector{T}, basis_dict::Dict{T,Int}, pm::Array{Int,2}) return new(G, basis, basis_dict, pm) end end +GroupRing{Gr<:Group}(G::Gr;initialise=true) = GroupRing{Gr, elem_type(G)}(G, initialise=initialise) + +GroupRing{Gr<:Group, T<:GroupElem}(G::Gr, b::Vector{T}, b_d::Dict{T,Int}, pm::Array{Int,2}) = GroupRing{Gr, T}(G, b, b_d, pm) + type GroupRingElem{T<:Number} <: RingElem coeffs::AbstractVector{T} parent::GroupRing From 4b86d5d075c8bd53b77fbd78d85963ef5d51669d Mon Sep 17 00:00:00 2001 From: kalmar Date: Tue, 6 Jun 2017 00:03:38 +0200 Subject: [PATCH 2/3] reparametrise parent call overloads --- src/GroupRings.jl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/GroupRings.jl b/src/GroupRings.jl index 8073cd4..5501d68 100644 --- a/src/GroupRings.jl +++ b/src/GroupRings.jl @@ -112,23 +112,23 @@ end # ############################################################################### -function (RG::GroupRing)(T::Type=Int) +function {Gr,T}(RG::GroupRing{Gr,T})(S::Type=Int) isdefined(RG, :basis) || throw("Complete the definition of GroupRing first") - return GroupRingElem(spzeros(T,length(RG.basis)), RG) + return GroupRingElem(spzeros(S,length(RG.basis)), RG) end -function (RG::GroupRing)(g::GroupElem, T::Type=Int) +function {Gr,T}(RG::GroupRing{Gr,T})(g::GroupElem, S::Type=Int) g = try RG.group(g) catch throw("Can't coerce $g to the underlying group of $RG") end - result = RG(T) - result[g] = one(T) + result = RG(S) + result[g] = one(S) return result end -function (RG::GroupRing)(x::AbstractVector) +function {Gr,T}(RG::GroupRing{Gr,T})(x::AbstractVector) length(x) == length(RG.basis) || throw("Can not coerce to $RG: lengths differ") result = RG(eltype(x)) result.coeffs = x From 61ed1f7870751cbcfdddbbec873b5494adbe0710 Mon Sep 17 00:00:00 2001 From: kalmar Date: Tue, 6 Jun 2017 11:46:15 +0200 Subject: [PATCH 3/3] rename groupring_mult[!] -> mul[!] --- src/GroupRings.jl | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/GroupRings.jl b/src/GroupRings.jl index 9e5ffd9..76b094c 100644 --- a/src/GroupRings.jl +++ b/src/GroupRings.jl @@ -296,7 +296,8 @@ end (+)(X::GroupRingElem, Y::GroupRingElem) = add(X,Y) (-)(X::GroupRingElem, Y::GroupRingElem) = add(X,-Y) -function groupring_mult!(X,Y,pm,result) +function mul!{T<:Number}(X::AbstractVector{T}, Y::AbstractVector{T}, + pm::Array{Int,2}, result::AbstractVector{T}) for (j,y) in enumerate(Y) if y != zero(eltype(Y)) for (i, index) in enumerate(pm[:,j]) @@ -309,17 +310,17 @@ function groupring_mult!(X,Y,pm,result) end end -function groupring_mult{T<:Number}(X::AbstractVector{T}, Y::AbstractVector{T}, +function mul{T<:Number}(X::AbstractVector{T}, Y::AbstractVector{T}, pm::Array{Int,2}) result = zeros(X) - groupring_mult!(X,Y,pm,result) + mul!(X,Y,pm,result) return result end -function groupring_mult(X::AbstractVector, Y::AbstractVector, pm::Array{Int,2}) +function mul(X::AbstractVector, Y::AbstractVector, pm::Array{Int,2}) T = promote_type(eltype(X), eltype(Y)) result = zeros(T, deepcopy(X)) - groupring_mult!(X, Y, pm, result) + mul!(X, Y, pm, result) return result end @@ -328,7 +329,7 @@ function *{T<:Number}(X::GroupRingElem{T}, Y::GroupRingElem{T}) "Elements don't seem to belong to the same Group Ring!")) RG = parent(X) isdefined(RG, :pm) || complete(RG) - result = groupring_mult(X.coeffs, Y.coeffs, RG.pm) + result = mul(X.coeffs, Y.coeffs, RG.pm) return GroupRingElem(result, RG) end @@ -338,7 +339,7 @@ function *{T<:Number, S<:Number}(X::GroupRingElem{T}, Y::GroupRingElem{S}) warn("Multiplying elements with different base rings!") RG = parent(X) isdefined(RG, :pm) || complete(RG) - result = groupring_mult(X.coeffs, Y.coeffs, RG.pm) + result = mul(X.coeffs, Y.coeffs, RG.pm) return GroupRingElem(result, RG) end