octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #54144] Why can't issorted() work on sparse ma


From: Dan Sebald
Subject: [Octave-bug-tracker] [bug #54144] Why can't issorted() work on sparse matrices?
Date: Mon, 18 Jun 2018 19:04:48 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0

Follow-up Comment #1, bug #54144 (project octave):

Actually, sorting on sparse matrices might work, while bug #54143 is covering
up this fact:


octave:15> X = sparse ([1 1], [3 4], [4 3], 1, 8)
X =

Compressed Column Sparse (rows = 1, cols = 8, nnz = 2 [25%])

  (1, 3) ->  4
  (1, 4) ->  3

octave:16> full(X)
ans =

   0   0   4   3   0   0   0   0

octave:17> sort(X)
ans =

Compressed Column Sparse (rows = 1, cols = 8, nnz = 2 [25%])

  (1, 7) ->  3
  (1, 8) ->  4

octave:18> full(sort(X))
ans =

   0   0   0   0   0   0   3   4

octave:21> issorted(X)
ans = 0
octave:22> issorted(sort(X))
ans = 1


If that is the case, then the attached changeset is all that is needed.

There is another use of the phrase "support sparse" in this file:


diff --git a/libinterp/corefcn/data.cc b/libinterp/corefcn/data.cc
--- a/libinterp/corefcn/data.cc
+++ b/libinterp/corefcn/data.cc
@@ -6702,8 +6702,6 @@ ordered lists.
 // Sort the rows of the matrix @var{a} according to the order
 // specified by @var{mode}, which can either be 'ascend' or 'descend'
 // and return the index vector corresponding to the sort order.
-//
-// This function does not yet support sparse matrices.
 
 // FIXME: Is this function used anymore?  12/14/2015
 DEFUN (__sort_rows_idx__, args, ,


I was going to remove that, but in this case that statement still holds. 
Furthermore, there is a FIXME question about whether this routine is even used
anymore, so maybe investigating and removing that routine is the better route.
 It appears that the script file sortrows() uses the above routine, and for
the sparse case it implements a row-by-row sort via a script
sort_rows_idx_generic().  Apparently, the sorting method of the
sort_rows_idx_generic() accepts sparse matrices.  For sparse matrices, the
generic script-based sort probably doesn't have the cost that full matrices
do.  I wonder if the better solution here is to move what is in sortrows.m
into the built-in routine __sort_rows_idx__ and call that routine "sortrows".

(file #44394)
    _______________________________________________________

Additional Item Attachment:

File name: octave-issorted_doc-djs2018jun18.patch Size:0 KB


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?54144>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]