bugGNU Octave - Bugs: bug #40467, cellfun ignores...

 
 

bug #40467: cellfun ignores UniformOutput=false sometimes & needs doc update

Submitter:  Markus Appel <mappel>
Submitted:  Mon 04 Nov 2013 09:46:23 AM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  jordigh
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sun 10 Nov 2013 02:57:33 AM UTC, comment #4: 

I have pushed a couple of fixes:

    http://hg.savannah.gnu.org/hgweb/octave/rev/5401637c3fa7
    http://hg.savannah.gnu.org/hgweb/octave/rev/38b726ed04c9

These should be part of the upcoming Octave release in a couple of weeks. Closing report.

Jordi GutiƩrrez Hermoso <jordigh>
Group Member
Wed 06 Nov 2013 08:05:56 PM UTC, comment #3: 

Thanks for the diagnosis. I guess I broke this... I'll work on fixing it.

Jordi GutiƩrrez Hermoso <jordigh>
Group Member
Tue 05 Nov 2013 01:39:23 AM UTC, comment #2: 

Confirmed. See cellfun.cc line 491:

http://hg.savannah.gnu.org/hgweb/octave/file/45e325002810/libinterp/corefcn/cellfun.cc#l491

The function attempts to call internal versions of certain named functions that it recognizes, even if they were passed in as a function handle instead of a string. This code path doesn't appear to respect the UniformOutput property.

Mike Miller <mtmiller>
Group Member
Mon 04 Nov 2013 05:06:13 PM UTC, comment #1: 

Update:

I was a bit too fast jumping too conclusions with "isclass", the documentation actually shows that a second argument is necessary which makes it work as expected.

Looking into Matlab R2012b I saw that calls of the form cellfun('isempty',...) are supported for backwards compatibility only and do not accept the "UniformOutput" property at all.

Here is another example of "UniformOutput" failing, this time with function handles:


octave-cli:3> cellfun(@isreal, {1 inf nan []}, "UniformOutput", false)
ans =

   1   1   1   1

octave-cli:4> cellfun(@iscomplex, {1 inf nan []}, "UniformOutput", false)
ans =
{
  [1,1] = 0
  [1,2] = 0
  [1,3] = 0
  [1,4] = 0
}


Markus Appel <mappel>
Mon 04 Nov 2013 09:46:23 AM UTC, original submission:  

cellfun presently has some issues:

(1)
For (most?) functions explicitly named in the documentation, UniformOutput=false is ignored:


octave-gui:21> cellfun('isempty', {1 inf nan []}, "UniformOutput", false)
ans =

   0   0   0   1

octave-gui:22> cellfun('isreal', {1 inf nan []}, "UniformOutput", false)
ans =

   1   1   1   1


(2)
The documented function 'isclass' does not exist (has it been renamed to 'isobject'?)


octave-gui:23> cellfun('isclass', {1 inf nan}, "UniformOutput", false)
error: cellfun: not enough arguments for "isclass"
octave-gui:23> help isclass
error: help: 'isclass' not found
octave-gui:23> cellfun('isobject', {1 inf nan}, "UniformOutput", false)
ans =
{
  [1,1] = 0
  [1,2] = 0
  [1,3] = 0
}


(3)
Personally, I find the documentation on "character string arguments" quite confusing:


Additionally, `cellfun' accepts an arbitrary function FUNC in the form of an inline function, function handle, or the name of a function (in a character string).  In the case of a character string argument, the function must accept a single argument named X, and it must return a string value.  The function can take one or more arguments, with the inputs arguments given by C, D, etc.


The part about "must return a string value" does not seem to be required, but the following form seems to be obsolete anyway:


octave-gui:26> cellfun('sin(x)', {1 2 inf nan}, "UniformOutput", false)
warning: cellfun: passing function body as a string is obsolete; please use anonymous functions
ans =
{
  [1,1] =  0.84147
  [1,2] =  0.90930
  [1,3] = NaN
  [1,4] = NaN
}


Cheers,
Markus

Markus Appel <mappel>

 

(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 jordigh (Posted a comment)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by mappel (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 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2013-11-10 jordigh StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2013-11-06 jordigh Assigned toNone jordigh
    2013-11-05 mtmiller StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-caa5.
    Corresponding source code