Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Sparse matrix indexing speed -- shape sensitivity
Date: Sun, 28 Aug 2011 07:24:11 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 34
Message-ID: <j3cqer$o66$1@newscl01ah.mathworks.com>
References: <j3bumn$9ts$1@newscl01ah.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
NNTP-Posting-Host: www-06-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1314516251 24774 172.30.248.38 (28 Aug 2011 07:24:11 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 28 Aug 2011 07:24:11 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:741476

The time is even worst for

A3=reshape(spalloc(1000,2000,500^2),2,[]);

tic
 A3(linearIndex)=rhs;
toc % 354.819217 seconds.

It can only be account on the way TMW programs it, and who knows what they do. 

All I know is my SETSPARSE function on FEX does much better than Matlab and time is consistent in three cases:

A4=A1;
A5=A2;
A6=A3;

tic
[i j] = ind2sub(size(A4),linearIndex);
A4=setsparse(A4,i,j,rhs);
toc %  0.045450 seconds.

tic
[i j] = ind2sub(size(A5),linearIndex);
A5=setsparse(A5,i,j,rhs);
toc %  0.037615 second

tic
[i j] = ind2sub(size(A6),linearIndex);
A6=setsparse(A6,i,j,rhs);
toc %  0.048041 seconds.

So there is no reason why it performs that bad with built-in assignment. This is one of the reasons I wrote this package. I'll delete it once they catch me.

Bruno