BUG DESCRIPTION:
----------------
For sparse input, gsort() is limited to sparse vectors.
This means that, with a small effort using matrix() on the result, a sparse matrix can be sorted only in the general "g" mode.
However, this work should be done internally.
In addition, "r" "c" "lr" and "lc" sorting modes are not available.
They should be implemented for 2D sparse matrices.
Request :
A) after [sv,k] = gsort(M, "g")
-----------------------------
=> size(sv)==size(M)
=> The returned k should
- have the size(M), as for dense M
- be sparse and focus on the position of non-zero terms.
- be such that we have:
v = spzeros(M); v(k>0) = M(k(k>0)); and(v==M) // => must be %T
B) For the "r" and "c" modes : After [sv,k] = gsort(M, "r"|"c")
------------------------------------------------------------
- With a dense matrix M, k is a matrix of size(M) without any zero.
- For a sparse M, a dense k could be really huge and run the computer out of memory.
=> k should
- have the size(M), as for dense inputs
- be sparse and focus on the position of non-zero terms,
- take the positions of zeros into account for the positions of non-zero terms.
C) For "lr" mode : after [sv,k] = gsort(M, "lr")
----------------------------------------------
- With a dense matrix M, k is a dense column of size(M,1) without any zero, such that sv = M(k,:).
- For a sparse M, we propose to always return a column k matching the cases
of sorting a column vector in "g" or "r" modes:
=> k is a sparse column of size(M,1) returning initial indices
only for rows having non-zero terms
=> we must have:
v = spzeros(M); v(k>0,:) = M(k(k>0),:); and(v==M) // => must be %T
D) For "lc" mode : as for "lr", transposed: after [sv,k] = gsort(M, "lc")
-----------------------------------------------------------------------
- With a dense matrix M, k is a dense row of size(M,2) without any zero, such that sv = M(:,k).
- For a sparse M, we propose to always return a row k matching the cases
of sorting a row vector in "g" or "r" modes:
=> k is a sparse row returning initial indices only for columns having non-zero terms
=> we must have:
v = spzeros(M); v(:,k>0) = M(:,k(k>0)); and(v==M) // => must be %T
ERROR LOG:
----------
--> gsort(sprand(2,3,0.5))
%sp_gsort
at line 32 of function %sp_gsort ( SCI\modules\elementary_functions\macros\%sp_gsort.sci line 45 )
in builtin gsort
gsort: Wrong size for input argument #1: sparse vectors expected.
HOW TO REPRODUCE THE BUG:
-------------------------
gsort(sprand(2,3,0.5))
OTHER INFORMATION:
------------------
See also the bug 15838.
Complex sparse matrices should also be accepted (after the bug 15825 will be fixed)