Thread Subject: Faster sparse from triplets

Subject: Faster sparse from triplets

From: Pietro

Date: 7 Feb, 2008 16:42:31

Message: 1 of 3

I have written my own version of repmat for use on sparse arrays,
because the default implementation creates big ones arrays for which
there is insufficient memory due to the dimensions involved.

My implementation basically involves repmatting the results of
find(...) so I end up with two index vectors and a values vector
representing the new repmatted array.

The problem comes when trying to convert those vectors into a sparse
array with sparse(x, y, values). It just takes far too long.

The dimensions of the vectors are in the region of 18e6 and the sparse
density is around 0.2. sprand can create a sparse of the same
dimensions and density in no time at all. How can I get sparse(x, y,
values) to speed up??

Have tried CXSparse's cs_sparse but no noticeable improvement.

Thanks.

Subject: Faster sparse from triplets

From: alan.larkin@gmail.com

Date: 7 Feb, 2008 21:37:35

Message: 2 of 3

On 7 Feb, 16:42, Pietro <pietro...@gmail.com> wrote:
> I have written my own version of repmat for use on sparse arrays,
> because the default implementation creates big ones arrays for which
> there is insufficient memory due to the dimensions involved.
>
> My implementation basically involves repmatting the results of
> find(...) so I end up with two index vectors and a values vector
> representing the new repmatted array.
>
> The problem comes when trying to convert those vectors into a sparse
> array with sparse(x, y, values). It just takes far too long.
>
> The dimensions of the vectors are in the region of 18e6 and the sparse
> density is around 0.2. sprand can create a sparse of the same
> dimensions and density in no time at all. How can I get sparse(x, y,
> values) to speed up??
>
> Have tried CXSparse's cs_sparse but no noticeable improvement.
>
> Thanks.

I had a similar problem and attempted a similar solution a while ago.
Its posted below if you want to compare. Unfortunately when I tried it
with the dimensions/density you mentioned it was way too slow to be
acceptable.

function B = sprepmat(A, M, N)
% SPREPMAT Space efficient repmat for sparse matrices
%
% A the matrix to be tiled
% M the number of times to tile vertically
% N the number of times to tile horizontally
%
[m, n] = size(A);
[x, y, values] = find(A);
if(m == 1)
x = x';
y = y';
values = values';
end
nz = length(values);

i = (0:nz * M * N - 1)';
B = sparse( x(mod(i, nz) + 1) + m * floor(i / (nz * N)), ...
y(mod(i, nz) + 1) + n * floor(mod(i, nz * N) / nz), ...
values(mod(i, nz) + 1) );

Subject: Faster sparse from triplets

From: Tim Davis

Date: 9 Feb, 2008 22:03:02

Message: 3 of 3

Pietro <pietromas@gmail.com> wrote in message
<b3058c25-ab52-422b-b0e2-9d1a87124808@e23g2000prf.googlegroups.com>...
> I have written my own version of repmat for use on sparse
arrays,
> because the default implementation creates big ones arrays
for which
> there is insufficient memory due to the dimensions involved.
>
> My implementation basically involves repmatting the results of
> find(...) so I end up with two index vectors and a values
vector
> representing the new repmatted array.
>
> The problem comes when trying to convert those vectors
into a sparse
> array with sparse(x, y, values). It just takes far too long.
>
> The dimensions of the vectors are in the region of 18e6
and the sparse
> density is around 0.2. sprand can create a sparse of the same
> dimensions and density in no time at all. How can I get
sparse(x, y,
> values) to speed up??
>
> Have tried CXSparse's cs_sparse but no noticeable improvement.
>
> Thanks.

Try CHOLMOD's "sparse2" function. It's much faster than
MATLAB's "sparse", particularly when the indices are unsorted.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
sparse Tim Davis 9 Feb, 2008 17:04:58
rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com