bugGNU Octave - Bugs: bug #47755, Access to object arrays

 
 

bug #47755: Access to object arrays

Submitter:  Guillaume <gyom>
Submitted:  Thu 21 Apr 2016 04:26:34 PM UTC
   
 
Category:  Classdef Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Confirmed Assigned to:  None
Originator Name:  Guillaume Open/Closed:  * Open
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Wed 05 Oct 2022 03:32:51 PM UTC, comment #9: 

just confirming the same behavior as comment #8 still exists in
Octave Version: 8.0.0 (hg id: 8b75954a4670)


Nicholas Jankowski <nrjank>
Group Member
Tue 16 Apr 2019 02:19:46 AM UTC, comment #8: 

Desired is to be compatible with Matlab.  Less a Roadmap, more a state of the art, is given in the wiki: https://wiki.octave.org/Classdef

What I can confirm is, that for the latest development release the original issue has not changed:


>> ver
----------------------------------------------------------------------
GNU Octave Version: 6.0.0 (hg id: 159402e52cfa)
GNU Octave License: GNU General Public License
Operating System: Linux 4.12.14-lp150.12.58-default #1 SMP Mon Apr 1 15:20:46 UTC 2019 (58fcc15) x86_64
----------------------------------------------------------------------

>> a(1) = myclass(1);
>> a(2) = myclass(2);

>> a.myprop
ans =  1
ans =  2
>> a.myprop()
error: can't perform indexing operation on array of myclass objects
>> myprop(a)
ans =

   1   2


Kai Torben Ohlhus <siko1056>
Group Member
Mon 15 Apr 2019 07:32:19 AM UTC, comment #7: 

Thanks for the reply.  Can you verify that the first calling behaviour is the desired behaviour for Octave 6, and that the other syntaxes will have the same behaviour as the first?

Is there a roadmap for what the Octave 6 classdef behaviour will look like?  For example MATLAB static method syntax is parsed but ignored, they act like instance methods but don't have the object passed in.

Peter Corke <petercorke>
Mon 15 Apr 2019 01:43:35 AM UTC, comment #6: 


> Are these different behaviours desired/documented?


Certainly not.  It is due to the fact, that classdef is not 100% Matlab compatible yet.  Recently, jwe improved things a lot, but it consumes a lot of time.  If you feel able to improve this for Octave 6, please don't hesitate to send us patches for this particular problem.

Otherwise you should stay with the first calling scheme to be compatible with both Octave and Matlab.

Kai Torben Ohlhus <siko1056>
Group Member
Sun 14 Apr 2019 03:10:38 AM UTC, comment #5: 

Using Octave 5.1 these issues are still present, but this bug seems to be dormant.

In MATLAB these are all identical:

myprop(a)
a.myprop
a.myprop()

and the object array a is passed to the method myprop().

In Octave each behaves differently:

myprop(a) is called once and passed the object array a
a.myprop is called on every element of a, the return value is the concatenation of the return value from every call to my prop
a.myprop() always gives an error

error: can't perform indexing operation on array of my class objects

but not clear what it is trying to index. If an argument is given inside the parentheses it is passed to the method, so it's not using as an index for a.  Octave certainly can perform indexing operations on this kind of object array, just not in this context.

Are these different behaviours desired/documented?  I'm trying to make some code as compatible as possible between MATLAB and Octave, and it'd be good to know where I stand.

Peter Corke <petercorke>
Wed 29 Jun 2016 10:32:48 AM UTC, comment #4: 

It never worked, I gave it an unsuitable item group. I think "Incorrect Result" fits better.

Kai Torben Ohlhus <siko1056>
Group Member
Wed 29 Jun 2016 10:11:27 AM UTC, comment #3: 

This is tagged as a "regression".  What version did it work in?

Lachlan Andrew <lachlan>
Mon 25 Apr 2016 02:31:17 PM UTC, comment #2: 

I can confirm the output of the original post and #1. Furthermore it should return the vector [1, 2] in any case.


>> ver
[snip]
MATLAB Version: 9.0.0.341360 (R2016a)
[snip]
Operating System: Linux 4.5.0-3-default #1 SMP PREEMPT Mon Mar 28 07:27:57 UTC 2016 (8cf0ce6) x86_64
[snip]

>> a.myprop
ans =
     1     2

>> a.myprop()
ans =
     1     2

>> myprop(a)
ans =
     1     2


The Octave's classdef implementation seems to be close to the behavior of a struct.

Matlab produces:

>> b = [struct('prop', 1), struct('prop',2)]
b =
1x2 struct array with fields:
    prop

>> b.prop
ans =
     1

ans =
     2


Octave produces:

>> b = [struct('prop', 1), struct('prop',2)]
b =

  1x2 struct array containing the fields:

    prop

>> b.prop
ans =  1
ans =  2


Kai Torben Ohlhus <siko1056>
Group Member
Thu 21 Apr 2016 05:06:32 PM UTC, comment #1: 

To be more precise, here is what happens with different syntax calls:


>> a.myprop
ans =  1
ans =  2
>> a.myprop()
error: can't perform indexing operation on array of myclass objects
>> myprop(a)
ans =
   1   2


Guillaume <gyom>
Thu 21 Apr 2016 04:26:34 PM UTC, original submission:  

Given a class like this:


classdef myclass
  properties
    prop;
  end
  methods
    function obj = myclass(val)
      obj.prop = val;
    end
    function val = myprop(obj)
      val =[obj.prop];
    end
  end
end


create an object array:


a(1) = myclass(1);
a(2) = myclass(2);


A call to myprop() property should return [1 2] but instead it returns:


>> a.myprop
ans =  1
ans =  2


Guillaume <gyom>

 

(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 (Updated the item)
  • -email is unavailable- added by nrjank (Posted a comment)
  • -email is unavailable- added by petercorke (Posted a comment)
  • -email is unavailable- added by lachlan (Posted a comment)
  • -email is unavailable- added by siko1056 (Posted a comment)
  • -email is unavailable- added by gyom (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 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2024-01-23 mmuetzel CategoryInterpreter Classdef
    2016-06-29 siko1056 Item GroupRegression Incorrect Result
    2016-04-25 siko1056 CategoryNone Interpreter
        Item GroupNone Regression
        StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code