bugGNU Octave - Bugs: bug #61898, [octave forge] (interval) subsref:...


bug #61898: [octave forge] (interval) subsref: Error when field syntax is used on non-scalar @class object

Submitted by:  Oliver Heimlich <oheim>
Submitted on:  Sat 22 Jan 2022 09:42:55 PM UTC
Category:  Octave Forge Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Regression
Status:  Wont Fix Assigned to:  None
Originator Name:  Oliver Heimlich Open/Closed:  * Closed
Release:  * 7.0.90 Operating System:  * Any
* Mandatory Fields

Add a New Comment (Rich Markup)

Comment Type & Canned Response:


( Jump to the original submission )

Sun 06 Feb 2022 10:29:16 PM UTC, comment #9: 

Closing report as the issue has now been addressed outside of core Octave.

Rik <rik5>
Project Administrator
Sun 06 Feb 2022 10:15:14 PM UTC, comment #8: 
Oliver Heimlich <oheim>
Sun 06 Feb 2022 01:18:13 PM UTC, comment #7: 

I agree.

Setting the category to "Octave Forge Package".

Markus Mützel <mmuetzel>
Project Member
Sat 05 Feb 2022 07:23:45 PM UTC, comment #6: 

In general Octave tries to be compatible with Matlab.  Hence, the long term direction is clear and Octave will change its behavior in the future to disallow this usage.

So now the question is simply timing.  Do we make this change now, between major versions 6 and 7, or do we announce that the change is coming and make it between versions 7 and 8?  I don't think there is much reason to wait and would propose that we make the change now (which amounts to not doing anything).

Pantxo has already pointed out how to modify the subsref.m file in the interval package to get this to work so this only requires that a new release of the interval package occur at the same time as Octave 7.

Rik <rik5>
Project Administrator
Fri 04 Feb 2022 05:27:30 PM UTC, comment #5: 

For the sake of completeness, in Matlab R2021a:

>> a = bug61898_subsref(1);
>> numel(a)

ans =


>> a.b

ans =

       bug61898_subsref object: 1-by-1

Markus Mützel <mmuetzel>
Project Member
Fri 04 Feb 2022 05:19:00 PM UTC, comment #4: 

I think I found a smaller reproducer. See attachment. Please check if this is actually reproducing this bug or it is something else.

In Octave 6.4.0:

>> a = bug61898_subsref([1 1]);

>> numel(a)

ans = 2
>> a.b

ans =

  <class bug61898_subsref>

In Octave 7.0.90:

>> a = bug61898_subsref([1 1]);

>> numel(a)

ans = 2
>> a.b

error: subsref: function called with too many outputs
error: called from

In Matlab R2021a:

>> a = bug61898_subsref([1 1]);
>> numel(a)

ans =


>> a.b
Error using bug61898_subsref/subsref
Too many output arguments.

So, while this is a change in behavior between Octave 6 and Octave 7, it seems to be compatible with Matlab to emit that error in this case.

Not sure what is more important. Matlab-compatiblity or backward-compatibility?

(file #52803)

Markus Mützel <mmuetzel>
Project Member
Thu 03 Feb 2022 01:44:11 AM UTC, comment #3: 

Is there a simple @class that we could use to check whether Matlab allows multiple outputs for '.' indexing?  Somewhere on Discourse there is a thread where we can post example code that we need run on Matlab and volunteers will do it and post the results.

Rik <rik5>
Project Administrator
Wed 02 Feb 2022 09:34:57 PM UTC, comment #2: 

I don't know if matlab allows user defined subsref to return an arbitrary number of outputs for "." indexing on an array of @class object, but, if so, the attached simple change in Octave should make it compatible (and make the workaround from comment #1 unnecessary).

(file #52794)

Pantxo Diribarne <pantxo>
Project Member
Wed 02 Feb 2022 09:03:02 PM UTC, comment #1: 

I don't know if it is a proper "fix", but, as a workaround, the following makes the example code work for me:

--- /home/pantxo/octave/interval-3.2.1/@infsup/subsref.m        2022-02-02 21:53:36.977512944 +0100
+++ /home/pantxo/.local/share/octave/api-v57/packages/interval-3.2.1/@infsup/subsref.m        2022-02-02 21:55:23.258076894 +0100
@@ -52,7 +52,7 @@
 ## Keywords: interval
 ## Created: 2014-10-29

-function A = subsref (A, S)
+function varargout = subsref (A, S)

   if (nargin ~= 2)
     print_usage ();
@@ -89,6 +89,8 @@
     A = subsref (A, S(2 : end));

+  varargout{1} = A;

 %!assert (infsup (magic (3))([1, 2, 3]) == magic (3)([1, 2, 3]));

In short, the builtin octave_class::subsref which ultimately calls the user defined one, is the same as for struct objects. For "." indexing on arrays it thus expects that subsref will return as many outputs as the number of elements in the array.

Pantxo Diribarne <pantxo>
Project Member
Sat 22 Jan 2022 09:42:55 PM UTC, original submission:  

When I use the field syntax a.b, where a is an object and numel (a) > 1, the interpreter produces an error and does not call the overridden subsref method of a's class.

It affects the Octave Forge interval package, where it produces some BIST failures. For example:

octave:1> x = infsup (0), numel (x)
x = [0]
ans = 1
octave:2> y = infsup ([0 0]), numel (y)
y = 1×2 interval vector

   [0]   [0]

ans = 2
octave:3> x.inf
ans = 0
octave:4> y.inf
error: subsref: function called with too many outputs
error: called from
octave:5> subsref (y, struct('type', '.', 'subs', 'inf'))
ans =

   0   0

Oliver Heimlich <oheim>


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

Attach Files:

Attached Files
file #52803:  @bug61898_subsref.zip added by mmuetzel (1KiB - application/x-zip-compressed)
file #52794:  bug61898.patch added by pantxo (2KiB - 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 siko1056 (Updated the item)
  • -email is unavailable- added by mmuetzel (Updated the item)
  • -email is unavailable- added by pantxo (Posted a comment)
  • -email is unavailable- added by rik5 (Updated the item)
  • -email is unavailable- added by oheim (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 project members can vote.





    Follow 12 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-02-06 rik5 StatusConfirmed => Wont Fix
        Open/ClosedOpen => Closed
    2022-02-06 siko1056 StatusIn Progress => Confirmed
    2022-02-06 mmuetzel CategoryInterpreter => Octave Forge Package
        Severity4 - Important => 3 - Normal
        Priority7 - High => 5 - Normal
        Summarysubsref: Error when field syntax is used on non-scalar @class object => [octave forge] (interval) subsref: Error when field syntax is used on non-scalar @class object
    2022-02-04 mmuetzel Attached File- => Added @bug61898_subsref.zip, #52803
    2022-02-02 pantxo Attached File- => Added bug61898.patch, #52794
        StatusNone => In Progress
    2022-01-31 rik5 Severity3 - Normal => 4 - Important
        Priority5 - Normal => 7 - High

    Back to the top

    Powered by Savane 3.9