Date: Aug 27, 2013 5:08 PM
Author: Michael
Subject: How to unroll for loop to take advantage of vectorization

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.