Hi,
I am struggling with how to speed up the following program. I have been trying to vectorize things, however, cannot get things to work. In the example below I have a 5x5 matrix, however, in practice the matrix is much larger, e.g., 5000 x 5000. Thanks so much for any help or suggestions.
-Michael
proc IML;
nP=5;
CM= {0 0.5 0.75 0 0.75 , 1 0 1 0 0.5 , 0.375 0.25 0 0.375 0.25 , 0 0 1 0 0, 1 0.333 0.667 0 0 };
print CM;
D = j(nP,nP,0);
do i1 = 1 to nP;
do i2 = i1+1 to nP; /* I only need to do the calculation on one half of the CM matrix as the resulting D matrix is symmetric */
do k=1 to nP;
if k ^= i1 && k ^= i2 then do; /* I don't use the cases when i1=i2 or i2=i1 */
D[i1,i2] = D[i1,i2] + (CM[i1,k] - CM[i2,k])**2 + (CM[k,i1] - CM[k,i2])**2;
end;
end;
D[i1,i2] = sqrt(D[i1,i2]);
D[i2,i1] = D[i1,i2];
end;
end;
print D;
end;
quit;
run;
... View more