bugGNU Octave - Bugs: bug #58411, cellfun with...


bug #58411: cellfun with "ErrorHandler" returns wrong message

Submitted by:  Muhali <muhali>
Submitted on:  Wed 20 May 2020 12:28:54 PM UTC  
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Regression
Status:  Confirmed Assigned to:  None
Originator Name:  Open/Closed:  Open
Release:  6.0.90 Operating System:  GNU/Linux

Add a New Comment (Rich Markup)

You are not logged in

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


Mon 01 Jun 2020 10:36:56 PM UTC, comment #2: 

This bug has two parts.  The fact that the last value has nonsense in it, rather than NaN, is due to the "ErrorHandler" routine itself.  The function "foo" cycles over the range 1:nargout.  However, when the calling form is

cellfun (...)

nargout is equal to 0 so no value is assigned by the ErrorHandler.  This is why the invocation

x = cellfun (...)

works because nargout is equal to 1 in this case and the for loop works correctly.

However, what should happen, according to Matlab, is that an error gets thrown because the function is supposed to supply a value.  Matlab emits an error that says that "UniformOutput" is true (default) but the function failed to produce a value for index 3.

By setting "UniformOutput" to false, both Matlab and Octave produce the correct result

cellfun (@factorial, {1,2,-3}, "ErrorHandler", @cellfoo, 'uniformoutput', false)

Rik <rik5>
Project Administrator
Wed 20 May 2020 03:34:14 PM UTC, comment #1: 

Confirmed.  This is a regression from 5.2.  The behavior is the same on the development branch as well.

The second part is interesting.  To be clear, the output value is incorrect when assigned to the default variable ("ans").  But is correct if there is an actual assignment to a variable.

Rik <rik5>
Project Administrator
Wed 20 May 2020 12:28:54 PM UTC, original submission:  

in continuation of bug #58280: the code

function varargout = foo (S, varargin)
   for i = 1 : nargout
      varargout{i} = NaN ;
cellfun ("factorial", {1,2,-3}, "ErrorHandler", @foo)

returns with ovtave-5

ans = factorial: all N must be real non-negative integers
ans =

    1.0000e+00    2.0000e+00   2.5233e-310

whereas octave-6 returns

ans =
ans =

    1.0000e+00    2.0000e+00   2.5233e-310

so the message is gone.

Moreover, the output of cellfun is only correct if I execute

fac = cellfun ("factorial", {1,2,-3}, "ErrorHandler", @foo)

which returns

fac =

     1     2   NaN

Muhali <muhali>


(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 (Posted a comment)
  • -email is unavailable- added by muhali (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
    2020-05-20 rik5 CategoryNone => Octave Function
        Item GroupNone => Regression
        StatusNone => Confirmed

    Back to the top

    Powered by Savane 3.5