I currently do something similar to the code below (though I have axis arrays instead of regular arrays):
A = 1:100
B = 1:200
C = 1:300
x = rand(length(A),length(B),length(C))
y = rand(length(B),length(C))
z = [
sum(y[b,c]*x[a,b,c] for b=B)
for a=A, c=C
]
I can see this potentially taking a very long time if my dimensions (A, B and C) get bigger, which they will eventually.
I know that in 2 dimensions I could do a vector/matrix operation which would be faster if I have a multi threaded processor (if I understand correctly), like the following:
x = rand(length(B), length(A))
y = rand(length(B), 1)
z = y' * x
I was wondering if there’s an obvious way to do that for the first example?
Thanks for the recomendation! I implemented tbeason’s use of view and actually got a ~ 20 times speed up, so that’s good enough for me. Makes me want to go through my code and figure out what else I can improve…