I have a 2D matrix, A, of size m x n, where n could be a very large number (e.g. n > 10000) and a multidimensional matrix of size m x m x n. So, for every column i in A, I want to compute A[:,i]'*B[:,:,i]. Below are the codes that I tried with the broadcasting feature in Julia. However, the performance of my code is quite slow. I am wondering whether the performance of my code could be improved. So, does someone have an idea of how I can improve the codes?
using LinearAlgebra;
m = 500;
n = 20000; # this could be a very large number.
vecA = rand(m,n);
matB = rand(m,m,n);
combinedAB = Array{Array{Float64,2},2}(undef,n,1);
for ii in eachindex(combinedAB)
combinedAB[ii] = [vecA[:,ii] matB[:,:,ii]];
end
# this is the result.
res = broadcast(eAB -> dotProd(eAB), combinedAB);
function dotProd(matZ::Array{Float64,2})
return sum(broadcast(dot,matZ[:,1],matZ[:,2:end]),dims=1);
end