Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: bsxfun runs faster in batches
Replies: 6   Last Post: Dec 24, 2012 8:03 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Daniel

Posts: 2
Registered: 7/4/12
bsxfun runs faster in batches
Posted: Jul 4, 2012 8:56 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

I want to add a column vector, length 66, to all columns in a matrix with about a million columns.

You would think that a single call to bsxfun would be the fastest way to do this - I certainly thought so - but batch processing a few thousand columns at a time seems to go somewhere between 2 or 3 times as fast...results are inconsistent (due to the details of memory management I suppose). I'm running in Matlab 2012a on a Mac.

a = rand(66,1E6);
b = rand(66,1);

tic
a = bsxfun(@plus,a,b);
toc;

tic
for ii=1:1E4:1E6
a(:,ii:ii+1E4-1) = bsxfun(@plus,a(:,ii:ii+1E4-1),b);
end
toc;

Is this behavior reproducible, and if so why does bsxfun self-optimise?
Also, is there a nice way to choose the batch size, or do I just have to try it with different values on every computer I might want to run the code on.

Thanks



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.