bugGNU Octave - Bugs: bug #60086, Matrix exponentiation fails for...

 
 

bug #60086: Matrix exponentiation fails for empty matrix

Submitter:  None
Submitted:  Sun 21 Feb 2021 04:02:04 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error or Warning
Status:  Fixed Assigned to:  None
Originator Name:  Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * dev
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 25 Feb 2021 04:20:46 PM UTC, comment #5: 

No response so I'm going to go ahead and close this report.

Rik <rik5>
Group administrator
Tue 23 Feb 2021 12:09:22 AM UTC, comment #4: 

I checked in a fix which returns an empty matrix of the appropriate type (single or double) whenever one of the base or exponent is empty.  See http://hg.savannah.gnu.org/hgweb/octave/rev/85998370816a.

Marking as Ready for Test.

Rik <rik5>
Group administrator
Mon 22 Feb 2021 05:51:06 PM UTC, comment #3: 

This seems pretty easy to fix.  The code for powers of a matrix is in libinterp/corefcn/xpow.cc.  There are many different cases, but the input validation all looks like this:


  octave_value retval;

  octave_idx_type nr = a.rows ();
  octave_idx_type nc = a.cols ();

  if (nr == 0 || nc == 0 || nr != nc)
    err_nonsquare_matrix ();


It would be easy enough to check for an empty matrix (nr == 0 || nc == 0) and immediately return an empty matrix.

Do we want to be fully Matlab compatible with respect to matrix dimensions?  Matlab issues an error when the matrix is empty, but not square.  For example,


zeros (0,2) ^ 2


I don't see the reasoning for that.  If the matrix is empty, then raising it to a power is still always going to be an empty matrix.  We should decide on this question before implementing a solution.

Rik <rik5>
Group administrator
Mon 22 Feb 2021 11:12:38 AM UTC, comment #2: 

Can anyone point out to the file where the binary operators are defined?

Harshit Joshi <uriahtor>
Sun 21 Feb 2021 05:25:39 PM UTC, comment #1: 

Confirmed.

Fwiw, the output in Matlab R2020a:

>> A = zeros(0,0);
>> A^2

ans =

     []


Markus Mützel <mmuetzel>
Group administrator
Sun 21 Feb 2021 04:02:04 PM UTC, original submission:  

Calling A^2 causes an error when A becomes a 0x0 matrix. Further, the error text is unrelated to the cause of the error.


A = zeros(0,0), A^2


Result:

A = [](0x0)
error: for x^y, only square matrix arguments are permitted and one argument must be scalar.  Use .^ for elementwise power.


Desired result: return an empty matrix.

Anonymous

 

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

Attach Files:
   
   
Comment:
   

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 (Posted a comment)
  • -email is unavailable- added by uriahtor (Posted a comment)
  • -email is unavailable- added by mmuetzel (Posted a comment)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-02-25 rik5 StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2021-02-23 rik5 StatusConfirmed Ready For Test
    2021-02-21 mmuetzel StatusNone Confirmed
        Operating SystemGNU/Linux Any

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code