bugGNU Octave - Bugs: bug #60726, nargout for {} in subsref() method...

 
 

bug #60726: nargout for {} in subsref() method does not match MATLAB

Submitter:  Ray Zimmerman <rdzman>
Submitted:  Thu 03 Jun 2021 06:55:47 PM UTC
   
 
Category:  Classdef Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Release: 
Operating System:  * Any Fixed Release:  10.1.0
Planned Release:  10.1.0
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Sat 01 Feb 2025 10:23:10 PM UTC, comment #9: 

I verified the patch works for the examples in this bug report.  Marking as Fixed and closing report.

Rik <rik5>
Group administrator
Tue 21 Jan 2025 02:57:09 PM UTC, comment #8: 

Thank you for your contribution.
The actual changes look good to me.

I fixed a typo in the new module.mk for the tests and adapted it slightly to be a bit closer to the coding style. I also updated the copyright year in the main test file.

Pushed with those modifications to the default branch:
https://hg.savannah.gnu.org/hgweb/octave/rev/19987fbe8adf

Marking as ready for test.

Markus Mützel <mmuetzel>
Group administrator
Tue 24 Dec 2024 04:08:23 PM UTC, comment #7: 

I have identified two more cases where nargout in Octave is different from nargout in Matlab. Applying the patch from file #56712 also eliminates the differences in those two cases (as well as the case from comment #5).

To see the two cases, we can define this simple class:

classdef class_bug60726 < handle
  methods
    function varargout = subsref(obj, s)
      varargout = num2cell(repelem(nargout,max(nargout,1)));
    end
  end
end


In Octave:

octave:> x(1).a
ans = 0
octave:> x{1}.a
ans = 0


In Matlab (or Octave with patch from file #56712 applied)

>> x(1).a
ans = 1
>> x{1}.a
ans = 1


There might be more corner cases, and it may be debatable whether Matlab's answer is better than Octave's, but I think it is good to increase compatibility.

I am attaching a patch that includes the changes from file #56712 and also some test cases.


(file #56713)

Fernando <tutissanalio>
Sun 22 Dec 2024 04:17:28 PM UTC, comment #6: 

This patch should fix it.

(file #56712)

Fernando <tutissanalio>
Mon 25 Nov 2024 05:56:31 PM UTC, comment #5: 

It looks like this issue was partially addressed by the fixes for bug #48693 and bug #63841.

However, with Octave 9.2, I am still getting 0 instead of 1 (as in Matlab) from the following line from the original post ...

x{1};


Ray Zimmerman <rdzman>
Sun 06 Jun 2021 08:10:09 AM UTC, comment #4: 

See bug #48693 for a patch fixing the issue.

Fernando <tutissanalio>
Sat 05 Jun 2021 03:44:21 PM UTC, comment #3: 

After having a closer look, I think this is a duplicate of bug #48693, filed in 2016.

Fernando <tutissanalio>
Fri 04 Jun 2021 05:22:13 PM UTC, comment #2: 

I think this could related to bug #60723 and Matlab's function numArgumentsFromSubscript:

https://www.mathworks.com/help/matlab/ref/numargumentsfromsubscript.html

Fernando <tutissanalio>
Fri 04 Jun 2021 03:48:47 PM UTC, comment #1: 

Same result on development branch of Octave (0,1,0,1).  Marking as Confirmed.

Rik <rik5>
Group administrator
Thu 03 Jun 2021 06:55:47 PM UTC, original submission:  

With the following simple classdef ...


classdef nargout_in_subsref_bug < handle
    properties
        c = num2cell(1:5);
    end
    methods
        function varargout = subsref(obj, s)
            disp(nargout)
            [varargout{1:nargout}] = obj.c{s(1).subs{:}};
        end
    end
end


... the following example produces different output on Octave vs. MATLAB.


x = nargout_in_subsref_bug();
x{1};
{x{1}};
x{[2 3]};
{x{[2 3]}};


Octave output:

0
1
0
1


MATLAB output:

     1

     1

     2

     2


In the examples I tried, nargout does seem to match for () and . indexing.

Ray Zimmerman <rdzman>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #56713:  bug-60726.patch added by tutissanalio (6KiB - text/x-patch)
file #56712:  bug-60726.patch added by tutissanalio (1KiB - text/x-patch)

 

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 mmuetzel (Updated the item)
  • -email is unavailable- added by tutissanalio (Posted a comment)
  • -email is unavailable- added by rdzman (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 11 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2025-02-01 rik5 StatusReady For Test Fixed
        Open/ClosedOpen Closed
        Fixed ReleaseNone 10.1.0
    2025-01-21 mmuetzel Planned ReleaseNone 10.1.0
    2025-01-21 mmuetzel StatusConfirmed Ready For Test
    2024-12-24 tutissanalio Attached File- Added bug-60726.patch, #56713
    2024-12-22 tutissanalio Attached File- Added bug-60726.patch, #56712
    2024-01-23 mmuetzel CategoryInterpreter Classdef
    2021-06-04 rik5 Carbon-CopyRemoved 72865 -
    2021-06-04 rik5 StatusNone Confirmed
        Release6.2.0 dev

    Back to the top

    Powered by Savane 3.15-ef91.
    Corresponding source code