bugGNU Octave - Bugs: bug #54142, The sort() and issorted() routines...


bug #54142: The sort() and issorted() routines for diagonal matrices isn't as fast as it should be

Submitted by:  Dan Sebald <sebald>
Submitted on:  Mon 18 Jun 2018 07:40:14 PM UTC  
Category:  Performance Severity:  1 - Wish
Priority:  5 - Normal Item Group:  Feature Request
Status:  Confirmed Assigned to:  None
Originator Name:  Open/Closed:  Open
Release:  dev Operating System:  Any

Add a New Comment(Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


Wed 25 Jul 2018 06:30:08 PM UTC, comment #1:

The place for this is in liboctave/array/DiagArray2.[h|cc]. The template for the header file can be borrowed from Array.h. Dan's code can then be placed in DiagArray2.cc.

Rik <rik5>
Project Administrator
Mon 18 Jun 2018 07:40:14 PM UTC, original submission:

In the bug report


is an analysis of nnz for diagonal matrices, with greatly improved speed when taking into consideration how sparse the diagonal matrix is.

A similar thing can be said for sort() applied to diagonal matrices. E.g.,

It should be possible to speed up this operation by noting that we can:

1) Construct an all-zeros matrix of the same size.
2) Take the diagonal vector and distribute it either to the starting or ending position of the colum (or row) of the zeros matrix. E.g.,

and the issorted() routine boils down to a series of logical statements:

1) If the matrix size is 2 or less along the direction of sort, use the full matrix sort. Not much penalty is incurred by that.
2) If the diagonal vector is all zeros, the matrix is sorted.
3) Otherwise, the matrix is not sorted.

Dan Sebald <sebald>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by rik5 (Updated the item)
  • -email is unavailable- added by sebald (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.




    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-06-19 rik5 Severity3 - Normal => 1 - Wish
        Item GroupNone => Feature Request
        StatusNone => Confirmed

    Back to the top

    Powered by Savane 3.4