bugGNU Octave - Bugs: bug #58572, cellfun calls overloaded functions...

 
 

bug #58572: cellfun calls overloaded functions for class method isnumeric called instead of built-in isnumeric

Submitted by:  A.R. Burgers <arb>
Submitted on:  Mon 15 Jun 2020 07:34:09 AM UTC  
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Regression
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  Closed
Release:  6.0.90 Operating System:  Any

Add a New Comment (Rich Markup)
   

You are not logged in

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

 

( Jump to the original submission)

Fri 10 Jul 2020 08:36:06 AM UTC, comment #8: 

Closing as fixed (see comment #7).

Markus Mützel <mmuetzel>
Project Member
Fri 10 Jul 2020 07:37:33 AM UTC, comment #7: 

this fixes the issue for me

A.R. Burgers <arb>
Mon 15 Jun 2020 08:52:20 PM UTC, comment #6: 

I pushed the following changeset on stable and merged with default:

http://hg.savannah.gnu.org/hgweb/octave/rev/1be719d8b375

John W. Eaton <jwe>
Project Administrator
Mon 15 Jun 2020 07:11:25 PM UTC, comment #5: 

@jwe: That seems to be the case.
I modified "use_num" like this:

    function rslt = use_num(obj)
      fh = @isnumeric;
      functions (fh)
      fh(obj)
      rslt = cellfun(fh, {'a_name'});
    end

The result is:

>> ci = c_tst;
use_num_result = ci.use_num

ans =

  struct with fields:

    function: 'isnumeric'
        type: 'classsimple'
        file: 'MATLAB built-in function'
       class: 'c_tst'

c_tst.isnumeric called

ans =

  logical

   1


use_num_result =

  logical

   0

And similarly for a function that isn't built-in:

classdef c2_tst
  methods
    function rslt = use_ff(obj)
      fh = @fullfile;
      functions (fh)
      fh(obj)
      rslt = cellfun(fh, {'a_name'});
    end
    function rslt = fullfile(obj)
      disp('c2_tst.fullfile called');
      rslt = true;
    end
  end
end

Results with Matlab R2020a:

>> res = c2.use_ff

ans =

  struct with fields:

    function: 'fullfile'
        type: 'classsimple'
        file: 'C:\Program Files\MATLAB\R2020a\toolbox\matlab\iofun\fullfile.m'
       class: 'c2_tst'

c2_tst.fullfile called

ans =

  logical

   1

Error using cellfun
Non-scalar in Uniform output, at index 1, output 1.
Set 'UniformOutput' to false.

Error in c2_tst/use_ff (line 7)
      rslt = cellfun(fh, {'a_name'});

"file" seems to be where the function handle dispatches to if the input is not the "class".

Markus Mützel <mmuetzel>
Project Member
Mon 15 Jun 2020 06:13:54 PM UTC, comment #4: 

Thanks.  So it knows that @isnumeric is defined inside the c_tst class but it does the dispatching correctly based on the argument types.  That makes sense, but I assume there is some other use case for this type of handle that makes use of the class info?  Also, it seems weird to me that it has the "file" field set to "MATLAB built-in function".  I mean, if you made a function call with this handle and passed a c_tst object to it, I assume you wouldn't call the built-in isnumeric function.

John W. Eaton <jwe>
Project Administrator
Mon 15 Jun 2020 05:57:05 PM UTC, comment #3: 

Results in Matlab R2020a with the updated "use_num" method:

>> ver = version
if exist ('OCTAVE_VERSION', 'builtin')
hg_id = eval('__octave_config_info__.hg_id');
end
ci = c_tst;
use_num_result = ci.use_num

ver =

    '9.8.0.1323502 (R2020a)'


ans =

  struct with fields:

    function: 'isnumeric'
        type: 'classsimple'
        file: 'MATLAB built-in function'
       class: 'c_tst'


use_num_result =

  logical

   0

Markus Mützel <mmuetzel>
Project Member
Mon 15 Jun 2020 04:22:37 PM UTC, comment #2: 

If you change the use_num method in the class to be

    function rslt = use_num(obj)
      fh = @isnumeric;
      functions (fh)
      rslt = cellfun(fh, {'a_name'});
    end

what info does it display about the function handle when you execute the test in Matlab?

John W. Eaton <jwe>
Project Administrator
Mon 15 Jun 2020 04:14:35 PM UTC, comment #1: 

Confirmed.  It seems that when cellfun looks for a function signature to match isnumeric() it is automatically pickup up the classdef version.  But, the signature for the classdef version is

bool = isnumeric (OBJECT)

and given that cellfun is actually calling

isnumeric ("STRING")

it should instead be picking up the built-in version of isnumeric which has that signature.

I'll add jwe to the CC list, although he will probably see this bug pretty quickly.

Rik <rik5>
Project Administrator
Mon 15 Jun 2020 07:34:09 AM UTC, original submission:  

This example involves a class that defines a method isnumeric.
In the example, since recent changes, the class method is now called, where previously the built-in method was called.

octave-5.2.0 (and matlab)

ver = 5.2.1
hg_id = 75a90bfc14b1+
use_num_result = 0

stable:

ver = 6.0.1
hg_id = 5a85e42a1be7
c_tst.isnumeric called
use_num_result = 1

class definition

classdef c_tst
  methods
    function rslt = use_num(obj)
      rslt = cellfun(@isnumeric, {'a_name'});
    end
    function rslt = isnumeric(obj)
      disp('c_tst.isnumeric called');
      rslt = true;
    end
  end
end

script:

ver = version
if exist ('OCTAVE_VERSION', 'builtin')
  hg_id = eval('__octave_config_info__.hg_id');
end
ci = c_tst;
use_num_result = ci.use_num

A.R. Burgers <arb>

 

(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 mmuetzel (Posted a comment)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by rik5
  • -email is unavailable- added by arb (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 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-07-10 mmuetzel StatusReady For Test => Fixed
        Open/ClosedOpen => Closed
    2020-06-15 jwe StatusConfirmed => Ready For Test
    2020-06-15 rik5 Item GroupIncorrect Result => Regression
        StatusNone => Confirmed
        Summaryclass method isnumeric called instead of built-in isnumeric => cellfun calls overloaded functions for class method isnumeric called instead of built-in isnumeric
        Carbon-Copy- => Added jwe

    Back to the top


    Powered by Savane 3.5