From 6e95eae583c48dac56869eaa98e72f7404aa1198 Mon Sep 17 00:00:00 2001 From: kalmar Date: Wed, 12 Jul 2017 14:31:51 +0200 Subject: [PATCH] convert only if type of the product and result disagree --- src/GroupRings.jl | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/GroupRings.jl b/src/GroupRings.jl index 494de1d..dad9466 100644 --- a/src/GroupRings.jl +++ b/src/GroupRings.jl @@ -315,7 +315,7 @@ end (+)(X::GroupRingElem, Y::GroupRingElem) = add(X,Y) (-)(X::GroupRingElem, Y::GroupRingElem) = add(X,-Y) -function mul!{T}(result::AbstractVector{T}, X::AbstractVector{T}, Y::AbstractVector{T}, pm::Array{Int,2}) +function mul!{T}(result::AbstractVector{T}, X::AbstractVector, Y::AbstractVector, pm::Array{Int,2}) z = zero(T) result .= z for (j,y) in enumerate(Y) @@ -339,15 +339,19 @@ function mul!{T}(result::GroupRingElem{T}, X::GroupRingElem{T}, Y::GroupRingElem return result end -function mul!(result::GroupRingElem, X::GroupRingElem, Y::GroupRingElem) - S, T, U = eltype(result), eltype(X), eltype(Y) - TT = promote_type(S, T, U) - if S != TT || T != TT || U != TT - warn("Types $S, $T, $U are not the same, promoting the result to $TT") - result.coeffs = convert(Array{TT},result.coeffs) +function mul!{T<:Number}(result::GroupRingElem{T}, X::GroupRingElem, Y::GroupRingElem) + if result === X + result = deepcopy(result) end - result = deepcopy(result) - mul!(result.coeffs, convert(Array{TT}, X.coeffs), convert(Array{TT}, Y.coeffs), parent(X).pm) + + TT = typeof(first(a.coeffs)*first(b.coeffs)) + + if TT != T + warn("Type of the result $T does not contain type of the product ($TT), promoting.") + result = convert(TT, result) + end + + mul!(result.coeffs, X.coeffs, Y.coeffs, parent(X).pm) return result end