The use of cell array with bsxfun, that would return cell array.

Hello,
I have two cell arrays x1{1x499}(1x5) and x2{1x499}(1x5) with variables of gpuArray and would like to subtract x2 from x1 and should return cell array x3{1x499}(1x5). I can achieve this with cellfun, but it is quite slow, especially when working with bigger arrays. Is there a way to make it work with bsxfun, because it can use multithreads? If I use bsxfun x3=bsxfun(@minus,[x1{:}],[x2{:}]), however it returns array of size (1x2495).

8 commentaires

Can you not convert your cell array to a numeric array since it appears all cells have a regular size? Everything is better with a numeric array than a cell array if it is possible at all.
Yes it is possible to keep all data in numeric 3D array size (1x5x499).Would this help, because I think bsxfun does not work with 3D arrays.
Sorry, I was wrong. It did work with 3D arrays.
If you are just doing a subtraction of two equal sized arrays why do you need bsxfun anyway?
I am looking for ways to speed up calculations in my algorithm. I thought bsxfun would even more speed up 3D array calculations when using gpuArray. Thus, bsxfun would apply calculations on multithreads, or am I wrong?
I doubt bsxfun is ever faster than a simple subtraction (or any other operator) on same size matrices. It can certainly be faster and more efficient than using repmat when you want to apply e.g. column-wise addition/subtraction in a 2d matrix, but the raw operators should be at their most optimal and will be overloaded for gpuArrays in an appropriately optimised manner I'm sure (but you can easily test the speed of one method vs another using the timeit function, or even just a tic-tic pair)
Thank You Adam for the clarification.
bsxfun is mostly redundant now anyway because of implicit scalar dimension expansion. Just use the raw operator.

Connectez-vous pour commenter.

Réponses (0)

Catégories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by