bugGNU Octave - Bugs: bug #54028, copy of non-handle class instance...

 
 

bug #54028: copy of non-handle class instance is not deep

Submitted by:  A.R. Burgers <arb>
Submitted on:  Thu 31 May 2018 09:36:37 PM UTC  
 
Category:  Interpreter Severity:  4 - Important
Priority:  5 - Normal Item Group:  Regression
Status:  Confirmed Assigned to:  None
Originator Name:  Open/Closed:  Open
Release:  4.4.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.

 

Wed 02 Jan 2019 04:25:22 PM UTC, comment #5: 

This is a big change which isn't going to be decided on and fixed before the 5.0 release so I am marking it as WON'T FIX at https://wiki.octave.org/Bug_Fix_List_-_5.0_Release#Bugs_marked_as_regressions.

Rik <rik5>
Project Administrator
Fri 29 Jun 2018 08:38:34 PM UTC, comment #4: 

Adding jwe to the CC list since this is probably going to require his understanding of when two symbol references to the same underlying variable are split (Copy-on-Write semantics).

I think I have a simpler example that uses only the object a (a.m).  In this case, a single object that is changed correctly invokes COW semantics and the variables are split as shown below.

octave:52> x.array = a
x =

  scalar structure containing the fields:

    array =

    <object a>


octave:53> y = x
y =

  scalar structure containing the fields:

    array =

    <object a>


octave:54> x.array.ap
ans =  1
octave:55> y.array.ap = 5;
octave:56> x.array.ap
ans =  1
octave:57> y.array.ap
ans =  5

However, the struct variable array is an object array then this no longer works.

octave:58> clear x y
octave:59> x.array = a
x =

  scalar structure containing the fields:

    array =

    <object a>


octave:60> x.array(2) = a
x =

  scalar structure containing the fields:

    array =

    <object array a>


octave:61> y = x;
octave:62> x.array(1).ap
ans =  1
octave:63> y.array(1).ap = 5;
octave:64> x.array(1).ap
ans =  5
octave:65> diary off

It would appear that the real issue is object arrays.  I can make the example even simpler by removing the struct.

octave:9> x = a
x =

<object a>

octave:10> x(2) = a
x =

<object array a>

octave:11> y = x
y =

<object array a>

octave:12> x(1).ap
ans =  1
octave:13> y(1).ap = 5
y =

<object array a>

octave:14> x(1).ap
ans =  5

Rik <rik5>
Project Administrator
Fri 29 Jun 2018 08:16:14 PM UTC, comment #3: 

This may be specific to arrays of objects.  I used this modified script

ver = version()
bi = b();
bi.a_array = [-1];
bi.a_array(end+1) = pi;
% make copy of bi to bi_copy
bi_copy = bi;
% change first element of object array in copy
bi_copy.a_array(1) = 2;
% report first element of object array in original
bi.a_array(1)

And running it produces,

ver = 4.4.0
ans = -1

Rik <rik5>
Project Administrator
Fri 29 Jun 2018 07:24:40 PM UTC, comment #2: 

I can't get it to work in 4.0.3

octave-4.0.3 -f
use_b
ver = 4.0.3
error: subsasgn: invalid indexing for object array assignment
error: called from
    use_b at line 8 column 23
error: assignment failed, or no method for 'object = scalar'
error: called from
    use_b at line 8 column 23
error: assignment failed, or no method for 'object = scalar'
error: called from
    use_b at line 8 column 23

However, on 4.2.0 - 4.2.2 it works

use_b
ver = 4.2.0
ans =  1

And on 4.4.0 it produces the wrong answer

use_b
ver = 4.4.0
ans =  2

Rik <rik5>
Project Administrator
Fri 08 Jun 2018 06:46:33 AM UTC, comment #1: 

This is regression: it works in 4.0.3, but not in 4.4.0

ver = 4.0.3
ans =  1

ver = 4.4.0
ans =  2

A.R. Burgers <arb>
Thu 31 May 2018 09:36:37 PM UTC, original submission:  

Copying a class does not create a copy of an object array property, where as matlab does make a deep copy in this case.

classdef b
  properties
    a_array;
  end
end

classdef a
  properties
    ap = 1;
  end
end

a script use_b.m that attempts a copy of an instance of class b, where a_array is an object array.

ver = version()
bi = b();
bi.a_array = a;
bi.a_array(end+1) = a;
% make copy of bi to bi_copy
bi_copy = bi;
% change first element of object array in copy
bi_copy.a_array(1).ap = 2;
% report first element of object array in original
bi.a_array(1).ap

output with octave

ver = 4.4.0
ans =  2

output with matlab

ver = 8.6.0.267246 (R2015b)
ans = 1

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

    Date Changed by Updated Field Previous Value => Replaced by
    2018-06-29 rik5 Carbon-Copy- => Added jwe
    2018-06-29 rik5 Severity3 - Normal => 4 - Important
        Item GroupMatlab Compatibility => Regression
        StatusNone => Confirmed

    Back to the top


    Powered by Savane 3.5