The Math Forum

Search All of the Math Forum:

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

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: How to unroll for loop to take advantage of vectorization
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  

Posts: 4
Registered: 8/26/13
How to unroll for loop to take advantage of vectorization
Posted: Aug 27, 2013 5:08 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

I need to find a fast way to unroll this for loop:

x_pts = rand(3,1000);
x_pts_sig = rand(3,1000);
s_pts = rand(3,10000);

dist_norm = zeros(size(x_pts,2),size(s_pts,2));
for ix_pts = 1:size(x_pts,2)
sig = [x_pts_sig(1,ix_pts) 0 0;0 x_pts_sig(2,ix_pts) 0;0 0 x_pts_sig(3,ix_pts)];
dist_ix_s = bsxfun(@minus,x_pts(:,ix_pts),s_pts);
dist_norm(ix_pts,:) = sum(dist_ix_s'/sig,2)';

I want to do this so I can take advantage of processing on a GPU.

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

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.