From 6ac5800379c1084f5f0fa6783010a55b972ca751 Mon Sep 17 00:00:00 2001 From: kalmar Date: Wed, 12 Jul 2017 20:53:17 +0200 Subject: [PATCH] allocation-free multiplication! # Conflicts: # src/GroupRings.jl --- src/GroupRings.jl | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/GroupRings.jl b/src/GroupRings.jl index 2487e3c..92bdc19 100644 --- a/src/GroupRings.jl +++ b/src/GroupRings.jl @@ -301,14 +301,15 @@ end (+)(X::GroupRingElem, Y::GroupRingElem) = add(X,Y) (-)(X::GroupRingElem, Y::GroupRingElem) = add(X,-Y) -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]) - if X[i] != zero(eltype(X)) - index == 0 && throw(ArgumentError("The product don't seem to belong to the span of basis!")) - result[index] += X[i]*y +function mul!{T}(result::AbstractVector{T}, X::AbstractVector, Y::AbstractVector, pm::Array{Int,2}) + z = zero(T) + result .= z + for j in eachindex(Y) + if Y[j] != z + for i in 1:size(pm,1) + if X[i] != z + pm[i,j] == 0 && throw(ArgumentError("The product don't seem to be supported on basis!")) + result[pm[i,j]] += X[i]*Y[j] end end end