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

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

[Octave-bug-tracker] [bug #59226] Function colperm is broken for matrice


From: anonymous
Subject: [Octave-bug-tracker] [bug #59226] Function colperm is broken for matrices with empty columns
Date: Tue, 6 Oct 2020 04:53:48 -0400 (EDT)
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0

URL:
  <https://savannah.gnu.org/bugs/?59226>

                 Summary: Function colperm is broken for matrices with empty
columns
                 Project: GNU Octave
            Submitted by: None
            Submitted on: Tue 06 Oct 2020 08:53:46 AM UTC
                Category: Octave Function
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: None
                  Status: None
             Assigned to: None
         Originator Name: Marcel Jacobse
        Originator Email: 
             Open/Closed: Open
                 Release: 5.2.0
         Discussion Lock: Any
        Operating System: Any

    _______________________________________________________

Details:

Example:

>> colperm([1,0;0,0])
ans = 1


Expected result:

ans =

   2   1


Empty columns are basically completely ignored, so that even the dimension of
the returned permutation vector is not correct. This is the code for the
function in version 5.2.0:

function p = colperm (s)

  if (nargin != 1)
    print_usage ();
  endif

  [i, j] = find (s);
  idx = find (diff ([j; Inf]) != 0);
  [~, p] = sort (idx - [0; idx(1:(end-1))]);

endfunction


The problem is that empty columns will not appear in that vector of column
indices 'j', and therefore will not appear in the vector of column-end indices
'idx'. I can not think of a simple solution for this problem with this
solution via 'find'.

Instead, I propose to implement this function via 'sum' instead. See the
attached patch. I tested with a few matrices from the SuiteSparse Matrix
Collection <https://sparse.tamu.edu/> on my Windows machine with an i7-9750H
and the new implementation also tends to be as fast or even faster than the
current implementation in most cases. Additionally, the new implementation
returns a column vector just like the other permutation functions ('amd' and
so on). That is another minor bug with the current implementation of
'colperm'.



    _______________________________________________________

File Attachments:


-------------------------------------------------------
Date: Tue 06 Oct 2020 08:53:46 AM UTC  Name: colperm_fix.patch  Size: 898B  
By: None

<http://savannah.gnu.org/bugs/download.php?file_id=49924>

    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?59226>

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




reply via email to

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