bugGNU Octave - Bugs: bug #51333, Reductions on an empty matrix is...

 
 

bug #51333: Reductions on an empty matrix is inconsistent

Submitted by:  Joel Dahne <urathai>
Submitted on:  Wed 28 Jun 2017 01:21:12 PM UTC  
 
Category: Octave FunctionSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Matlab Compatibility
Status: ConfirmedAssigned to: None
Originator Name: Open/Closed: Open
Release: devOperating System: GNU/Linux

Add a New Comment(Rich Markup)
   

You are not logged in

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

 

Fri 30 Jun 2017 07:33:38 AM UTC, comment #2:

Yes, that's what I found as well. This means that if we would choose to go with Matlabs version it is just a matter of adding a check for "dim < 0" in the following if-statement.

For "dot" we add, right after the definition of dimx and dimy,

if we go with the version Octave has now. If we choose the matlab version we also add "nargin == 2" to the condition.

I don't know if we should go with the Matlab version, but either way I think it makes sense to do the changes to "dot".

Joel Dahne <urathai>
Thu 29 Jun 2017 10:24:56 PM UTC, comment #1:

Applies for the development version as well.

Digging into the code of "sum", "xsum", "prod", "sumsq" of an double NDArray, I found the inline function "do_mx_red_op" to be called in any case. According to a comment

https://hg.savannah.gnu.org/hgweb/octave/file/tip/liboctave/operators/mx-inlines.cc#l1537

it has to do with the described problem.

For "dot" the situation might be easier, as it is a seperate file which could check for empty input values:

https://hg.savannah.gnu.org/hgweb/octave/file/tip/libinterp/corefcn/dot.cc#l67

Kai Torben Ohlhus <siko1056>
Project Member
Wed 28 Jun 2017 01:21:12 PM UTC, original submission:

Some of the reduction functions have inconsistent handling of empty matrices. They also differ slightly to how Matlab handles it. The function I have looked at are sum, sumsq, prod and dot but it might hold true for other reduction functions as well.

Both sum and prod have the convention that the empty matrix returns the unit, i.e.

But this does not hold true for dot

I think it would be more natural for dot to also return 0 here. This is also how Matlab does it

Further I noticed that Matlab and Octave handles the empty matrix differently when a dimension is specified. In Octave we have

Looking at the code for Octaves reduction function we in fact have a explicit conversion from [] to a matrix of size 1x0 (commented as an inconsistency). In Matlab we instead have

When no dimension is specified it handles the empty matrix in a special way. But when a dimension is specified it handles it like any other matrix.

Joel Dahne <urathai>

 

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

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by siko1056 (Posted a comment)
  • -unavailable- added by urathai (Submitted the item)
  •  

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

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 2 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Thu 29 Jun 2017 10:24:56 PM UTCsiko1056StatusNone=>Confirmed
      Release4.2.1=>dev

    Back to the top


    Powered by Savane 3.1-cleanup1