help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Random access loops performing slowly


From: Bhaskar Mehta
Subject: Random access loops performing slowly
Date: Mon, 15 Oct 2007 09:42:45 +0200

Dear All,
I have being doing some form of matrix factorization, where I iterate through 
all non zeros of a sparse matrix
I use find/spfind to find all non zeros and then update two separate matrices 
with the found indices

[i j vals]=find(Z);
For k=1:length(i)
 ## access U(i(k),:):
## access V(j(k),: );
end

U, V are zeros(N,2), and zeros(M,2) respectively, where size(Z) is M x N.


Such loops such *extremely* slowly: 10 seconds on a fast server vs 0.3 seconds 
on a laptop with Matlab.
When more than one access is made in a loop to U(i(k),:): ), the speed is even 
slower. I have provided an example of a loop which runs even slower.

I additionally get an error with octave → “error: can't perform indexing 
operations for <unknown type> type”

Can any wise guys help me with this? I would be much obliged.
Best regards,
Bhaskar




Code is below

Z=bmmread('sorted_movielens_144_test_users.txt');
U=ones(size(Z,1),2)*0.01;
V=ones(size(Z,2),2)*0.01;
tic;
[i j vals]=find(Z);
k=0;
for val=1:length(i)
U(i(val),1)=U(i(val),1) + 0.02*(vals(val)-U(i(val),:)*V(j(val),:)');
V(j(val),1)=V(i(val),1) + 0.02*(vals(val)-U(i(val),:)*V(j(val),:)');
end
 
T=toc
tic
k=nnz(Z);
for val=1:k
U(mod(val,size(Z,1))+1,1)=U(mod(val,size(Z,1))+1,1) + 
0.02*((val)-U(mod(val,size(Z,1))+1,:)*V(mod(val,size(Z,2))+1,:)');
V(mod(val,size(Z,2))+1,1)=V(mod(val,size(Z,2))+1,1) + 
0.02*(vals(val)-U(mod(val,size(Z,1))+1,:)*V(mod(val,size(Z,1))+1,:)');
end
 
T=toc
 
Octave >> test.m
T =  10.930
T =  75.816
error: can't perform indexing operations for <unknown type> type

Matlab >> 
>> test

T =
    0.7475

T =
    3.4960
 


------------------------------------------------------
Bhaskar Mehta, 
Researcher, L3S Forschungszentrum
Appelstrasse 4 Hannover, Germany
Phone: +49 511 762 17761
------------------------------------------------------





reply via email to

[Prev in Thread] Current Thread [Next in Thread]