bugGNU Octave - Bugs: bug #55264, mean([]) throws division-by-zero...

 
 

bug #55264: mean([]) throws division-by-zero warning

Submitter:  Hartmut <hardy>
Submitted:  Fri 21 Dec 2018 08:30:31 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 4.4.1 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Fri 21 Dec 2018 10:20:03 PM UTC, comment #6: 

I pushed a temporary fix to stable (https://hg.savannah.gnu.org/hgweb/octave/rev/e95e17d6b6dc).  I just disable the printing of the warning itself, rather than trying to identify the special case and fix it.  Benchmarking shows that the call to disable the warning is 0.1 milliseconds so that's okay for now.

Rik <rik5>
Group administrator
Fri 21 Dec 2018 09:46:33 PM UTC, comment #5: 

If this general behavior is really decided and planned to be changed, soon, in the upcomeing Octave 6 branch, then I don't see the necessity to put a code change in mean.m (and mark it as fixme at the same time).

@Mike: Thanks for the note in bug #46650.

Then let's just CLOSE this issue (as duplicate of bug #46650).


Hartmut <hardy>
Fri 21 Dec 2018 09:39:48 PM UTC, comment #4: 

I just added an update to that other bug report so others don't assume it has been abandoned.

I also don't think this is accurately described as a Matlab compatibility issue.

And remember there is a possibility that a special case may take care of this, and may actually speed up the case when the input is empty, but will probably slightly slow down the common case of calling mean on a non-empty array because of the additional branching.

Mike Miller <mtmiller>
Group Member
Fri 21 Dec 2018 09:30:01 PM UTC, comment #3: 

The decision has already been made to remove the division-by-zero warning, so there is no controversy.  However, it's certainly not going to be a part of version 5.0. 

I think it would be okay to add a special case, temporarily.  Make sure it is well marked with a FIXME note to remove it as soon as bug #46650 is cleared.

Also, take care to preserve both the class and size of the input in the eventual output NaN.  As it exists today, for example.


octave:3> mean (single ([]))
warning: division by zero
warning: called from
    mean at line 149 column 9
ans =  NaN
octave:4> class (ans)
ans = single
octave:5> mean (zeros (1,3,0,5))
ans = [](1x1x0x5)

octave:6> mean (zeros (1,0,2), 2)
warning: division by zero
warning: called from
    mean at line 149 column 9
ans =

ans(:,:,1) =  NaN
ans(:,:,2) =  NaN



Rik <rik5>
Group administrator
Fri 21 Dec 2018 09:02:36 PM UTC, comment #2: 

I think in "mean" there should be no need to actually do a division by zero, just because the user inputs an empty matrix. Couldn't we simply avoid this division by zero itself by some kind of if-statement?

I would prefer to see this issue treated seperatly from the general case, probably in the code of "mean". Because this general case of muting this warning by default (as is discussed in bug #46650) is probably more controversal and therefore might take longer time to agree on.

Hartmut <hardy>
Fri 21 Dec 2018 08:50:40 PM UTC, comment #1: 

There is already bug #46650 about disabling the division-by-zero warning by default. I think this can be closed as a duplicate, do you agree?

Mike Miller <mtmiller>
Group Member
Fri 21 Dec 2018 08:30:31 PM UTC, original submission:  

In Matlab (R2018b) the command the mean of an empty matrix "mean([])" simply returns NaN. No warning is issued.

In Octave (4.4.1) the same command "mean([])" also returns NaN. But we additionally issue a warning message "division by zero".

This current Octave behavior

  • is incompatible to Matlab
  • gives this disturbing warning massage in a test of the wiener2 function in the image package (this is what bothers me more...)


Could we remove the Octave warning message of "mean" for this case?

Hartmut <hardy>

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Digest:
   bug dependencies.

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 hardy (Submitted the item)
  •  

    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
    2018-12-21 rik5 StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2018-12-21 rik5 StatusNone Confirmed
        Summarymean([]) throws incompatible warning mean([]) throws division-by-zero warning
    2018-12-21 mtmiller Dependencies- Depends on bugs #46650

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code