[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bsxfun and sparse matrices
From: |
Luca Citi |
Subject: |
Re: bsxfun and sparse matrices |
Date: |
Sat, 19 May 2012 19:51:51 -0400 |
Hi Jordi,
thanks for your input. Sorry about the terminology.
The version I have is "f49e47ab83ca tip".
In my example speye was just a quick way to create a sparse matrix for
testing purposes. The matrices I work with don't have such structure.
Matlab does handle bsxfun and sparse matrices the smart way. Right now
octave probably converts the matrix to full and then does the
operation. In fact:
X = speye(6000);
W = 1:6000;
Xf = full(X);
tic; for i = 1:100; XW = bsxfun(@times, X, W); end; toc
% takes approx 40s
tic; for i = 1:100; XW = bsxfun(@times, Xf, W); end; toc
% takes approx 20s
i.e., the sparse version is much slower (very likely because it is
converted to full first).
In matlab, the same takes
tic; for i = 1:100; XW = bsxfun(@times, X, W); end; toc
% takes approx 0.45s
tic; for i = 1:100; XW = bsxfun(@times, Xf, W); end; toc
% takes approx 17s
i.e., the sparse version is roughly 40 times faster.
I'll start looking into it. Thanks for the pointers!
Luca