Hi there,
I need to perform many matrix multiplications as follows. Here I proposed two functions (f1 and f2). I am wondering whether we could improve the speed of the function f2 further? Thanks in advance!
using LinearAlgebra
f1(C,X,Y,Z,T,x) = C .= .-x[1].*X*X' .- x[2].*Y*Y' .+ x[3].*Z*T;
function f2(C,X,Y,Z,T,x)
x1 = -x[1]
x2 = -x[2]
x3 = x[3]
fill!(C,0.0)
BLAS.syrk!('L', 'N', x1, X, 1.0, C)
BLAS.syrk!('L', 'N', x2, Y, 1.0, C)
conSym(C)
mul!(C, Z, T, x3, 1.0)
end
function conSym(A)
@inbounds for ii=1:size(A,1)-1
for jj=ii+1:size(A,1)
A[ii,jj] = A[jj,ii]
end
end
end
v = 600;
r = 3;
b1 = 60;
b2 = 90;
x = rand(3);
C1 = zeros(Float64,v,v);
C2 = zeros(Float64,v,v);
C3 = zeros(Float64,v,v);
X = rand(v,b1);
Y = rand(v,b2);
Z = rand(v,v*r);
T = rand(v*r,v) ;
@time f1(C1,X,Y,Z,T,x);
@time f2(C2,X,Y,Z,T,x);
@test all(C1 .β C2);