Add a New Comment (Rich Markup)
Comment Type & Canned Response: None None > Multiple Canned Responses Fixed in development Crash with no stack trace Already fixed in newer version Fixed in stable Bad description Bad description and crash Bad stack trace Obsolete version Duplicate and not fixed Duplicate and needs more info Duplicate and fixed Need info and old
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.
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
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
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
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
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
(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
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.
Please enter the title of George Orwell's famous dystopian book (it's a date):
Follow 4 latest changes.
Copyright © 2022 Free Software Foundation, Inc. Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved. The Levitating, Meditating, Flute-playing Gnu logo is a GNU GPL'ed image provided by the Nevrax Design Team. Source Code
Powered by Savane 3.9