Multiply slices of a 4D array with vectors without nested loops? Is there a function comparable to pagefun for the CPU?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Petter Stefansson
le 15 Sep 2016
Modifié(e) : James Tursa
le 15 Sep 2016
I want to multiply each 2D matrix slice of a 4D matrix, X, with a number of vectors, stored in Beta. If I was doing it on the GPU a function like pagefun would be perfect for this since it passes on slices of high dimensional arrays so they can be done in parallel. But since that function does not exist on the CPU I’m really struggling to find an efficient way of writing this. Right now I have this horrible nested for-loop:
for a = 1 : 10
for b = 1 : 245
Y(:,a,b) = X(:,:,a,b) * Beta(:,b,a);
end
end
% size(X) = 19000 x 13 x 10 x 245
% size(Beta) = 13 x 245 x 10
Which is as ugly as it is slow. Can anyone give be some tips on how this can be done in a better and faster way without nested loops? (The Y variable is of course pre-allocated before I run this).
0 commentaires
Réponse acceptée
James Tursa
le 15 Sep 2016
Modifié(e) : James Tursa
le 15 Sep 2016
Some FEX options to consider (some of them involve mex routines):
You will probably need to do some up-front reshaping to use these.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!