bugGNU Octave - Bugs: bug #53906, Cannot make an object array with...

 
 

bug #53906: Cannot make an object array with square brackets

Submitted by:  Richard <crobar>
Submitted on:  Tue 15 May 2018 10:34:24 AM UTC  
 
Category:  Interpreter Severity:  2 - Minor
Priority:  3 - Low Item Group:  Matlab Compatibility
Status:  Confirmed Assigned to:  None
Originator Name:  Richard Crozier Open/Closed:  Open
Release:  5.1.0 Operating System:  Any

Add a New Comment (Rich Markup)
   

You are not logged in

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

 

Mon 25 Feb 2019 11:05:14 AM UTC, comment #5:

see also bug #44665

Amro <amro_octave>
Sun 01 Jul 2018 07:40:08 AM UTC, comment #4:

> So Matlab defines a default implementation of cat/horzcat/vertcat for classes?


Yep. It works like concatenating structs, plus the inputs are implicitly converted to the class of the left-most, superior-most object. All the related structural operations (repmat, ctranspose, circshift, ()-referencing, etc) are similarly defined.

Conversely, you can dot-reference into an array of objects, and it extracts fields into a comma-separated list.

Example:

Person class:

classdef Person
    properties
        firstName
        lastName
    end
    methods
        function this = Person(first, last)
            if nargin == 0
                return
            end
            this.firstName = first;
            this.lastName = last;
        end
    end
end

Behavior:

>> p = Person('Alice', 'Foo')
p =
  Person with properties:

    firstName: 'Alice'
     lastName: 'Foo'
>> p2 = Person('Bob', 'Bar')
p2 =
  Person with properties:

    firstName: 'Bob'
     lastName: 'Bar'
>> pp = [p p2]
pp =
  1×2 Person array with properties:

    firstName
    lastName

>> pp.firstName
ans =
    'Alice'
ans =
    'Bob'
>> {pp.firstName}
ans =
  1×2 cell array
    {'Alice'}    {'Bob'}
>> pp(4) = Person('Carol','Baz')
pp =
  1×4 Person array with properties:

    firstName
    lastName

>> pp.firstName
ans =
    'Alice'
ans =
    'Bob'
ans =
     []
ans =
    'Carol'
>>

Andrew Janke <apjanke>
Tue 15 May 2018 06:28:20 PM UTC, comment #3:

It works with handle classes without method overloading.

Richard <crobar>
Tue 15 May 2018 05:28:48 PM UTC, comment #2:

So Matlab defines a default implementation of cat/horzcat/vertcat for classes? Does this only apply to value classes or can handle classes also be concatenated without any method overloading?

Mike Miller <mtmiller>
Project Administrator
Tue 15 May 2018 10:49:51 AM UTC, comment #1:

cat doesn't work either:

>> z = cat (2, x, y)
warning: struct: converting a classdef object into a struct overrides the access restrictions defined for properties. All properties are returned, including private and protected ones.
error: invalid conversion of multi-dimensional struct to scalar struct

Richard <crobar>
Tue 15 May 2018 10:34:24 AM UTC, original submission:

Making an array of classdef objects using square barckets like below does not work in octave:

>> x = method_debug_test ()
x =

<object method_debug_test>

>> y = method_debug_test ()
y =

<object method_debug_test>

>> z = [x, y]
warning: struct: converting a classdef object into a struct overrides the access restrictions defined for properties. All properties are returned, including private and protected ones.
error: invalid conversion of multi-dimensional struct to scalar struct
>>

In matlab I get:

>> x = method_debug_test ()

x =

  method_debug_test with no properties.

>> y = method_debug_test ()

y =

  method_debug_test with no properties.

>> [x, y]

ans =

  1×2 method_debug_test array with no properties.

Richard <crobar>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #44160:  method_debug_test.m added by crobar (169B - text/x-objcsrc)

 

Digest:
   bug dependencies.

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 amro_octave (Posted a comment)
  • -email is unavailable- added by amro_octave
  • -email is unavailable- added by jwe (Updated the item)
  • -email is unavailable- added by apjanke (Posted a comment)
  • -email is unavailable- added by crobar (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 14 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-05-09 siko1056 Severity1 - Wish => 2 - Minor
        Item GroupFeature Request => Matlab Compatibility
        StatusNeed Info => Confirmed
        Release4.4.0 => 5.1.0
        Operating SystemGNU/Linux => Any
        Dependencies- => Depends on bugs #44665
    2019-02-25 mtmiller Carbon-CopyRemoved 80942 => -
    2019-02-25 amro_octave Carbon-Copy- => Added amro_octave
    2019-01-12 jwe Severity3 - Normal => 1 - Wish
        Priority5 - Normal => 3 - Low
        Item GroupMatlab Compatibility => Feature Request
    2018-05-15 mtmiller CategoryNone => Interpreter
        StatusNone => Need Info
    2018-05-15 crobar Attached File- => Added method_debug_test.m, #44160

    Back to the top


    Powered by Savane 3.4