0
Fixed

Spare matrix division by a scalar

Adam Rancon fa 9 anys updated by Pavel Holoborodko fa 9 anys 7
I have a problem when I try to divide a sparse matrix by a scalar. These few lines work perfectly in Matlab
norm0=max(abs(M(:)))
M=M/norm0
where M is a (possibly sparse) matrix.
Using the toolbox, it only works if M is full, and for a sparse matrix I get

One or more output arguments not assigned during call to "mpimpl".
Error in / (line 1055)
r = mpimpl(35,x,y);


Is there a way to get around that efficiently ?

Also, is there any chances that the function svds will be implemented soon ?

Adam 
Hello.

A similar error occours for

M./norm0
M.*norm0
But M*norm0 works, so for now

M=[12,1,1,1;0,1,1,0;0,1,0,1;0,0,0,1];
Msparsemp=mp(sparse(M));
norm0=max(abs(Msparsemp(:)));
Msparsemp = Msparsemp*(1/norm0);
Indeed, thanks for your input.
I tried M*1/norm0 which did not work, but no with the brackets.

However, it seems to me that max(M) with M sparse is really not optimized : for some reason, my M is initialized as a very large sparse matrice of size 4096*4096 but with only 16 non-zero elements. It takes almost 30 seconds to find the largest element, whereas if I put all the non-zero elements in a separate matrix, it takes a mere 0.04 seconds.

Adam
I actually do not use sparse matrizes but I think it was implemented not long ago so it might be still in development.

Best regards,
Michael
Under review
Element-wise division and multiplication with sparse matrices weren't implemented....

Until now - I have just released the updated version of toolbox with the operations.
Now only for Windows: http://goo.gl/pMXV3.

Mac OSX & Linux will be available later today - after re-compilation and unit tests.

As you know, sparse matrices are new feature in toolbox - functions are added (almost) every day.

Because of the limited (but growing) functionality for sparse matrices, we suggest the following workflow (if applicable):
1. Do all math. operations and manipulations with non-zero elements stored as vectors. 
2. Build the sparse matrix from vector of prepared non-zeros and their coordinates (function sparse()).
3. Solve the resulting sparse matrix against different rhs or use in iterative processes.

Toolbox has necessary solvers and optimized SpMV operations needed for step 3 - it has been our priority from the beginning.

This workflow is not perfect, but we lift the limitations with every release.

Now we are working on eigs(). The svds() will be added right after eigs() - as two are related.

The min/max has no support for sparse matrices (both convert it to full matrix = slow).
Will update both functions in next micro-updates shortly.

Michael, thank you very much for your help!
Updated toolbox for *NIX platforms (same links as always):

GNU Linux:
Advanpix Toolbox for Linux

MacOSX:
Advanpix Toolbox for Mac OSX

max/min for sparse matrices will be added shortly in next micro-update.