help-octave
[Top][All Lists]
Advanced

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

RE: Random access loops performing slowly


From: Bhaskar Mehta
Subject: RE: Random access loops performing slowly
Date: Mon, 15 Oct 2007 11:01:18 +0200

As a followup, the matrix I mention is at
http://www.l3s.de/~mehta/sorted_movielens_144_test_users.txt

The  simple bmmread script reads the matrix market sparse format for
octave/matlab (see end of email for code). I run octave 2.9.14

Would someone be willing to try my code on octave 2.9.15 and see if the
problem has been fixed ?
Best regards,
Bhaskar 

function out=bmmread(k)

Y=load(k);
out=spconvert(Y(2:end,:));



-----Original Message-----
From: Bhaskar Mehta [mailto:address@hidden 
Sent: Monday, October 15, 2007 9:43 AM
To: address@hidden
Subject: Random access loops performing slowly

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
------------------------------------------------------



_______________________________________________
Help-octave mailing list
address@hidden
https://www.cae.wisc.edu/mailman/listinfo/help-octave



reply via email to

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