Tue 14 Feb 2017 10:33:40 AM UTC, comment #15:
ok, but if this is the case, this should be explicitly documented
as is documented that constructor with no argument shall return the default object value.
One should say that subsasn
shall use the default value for padding.
|
Mon 06 Feb 2017 07:58:32 PM UTC, comment #14:
> but I assume a 'default object' is defined when one is created
Yes, "Ideally, even when the constructor is called with no arguments it should return a valid object." https://www.gnu.org/software/octave/doc/interpreter/Creating-a-Class.html
(I seem to remember this is also needed to support save/load).
If the class overrides "subsasn" then it may need to deal with this padding issue by itself. I've just [patched Symbolic to do so](https://github.com/cbm755/octsympy/pull/760).
|
Sun 05 Feb 2017 06:57:59 PM UTC, comment #13:
I believe the following Matlab documentation page describes how it handles indexed assignment, including what it does if the object doesn't exist:
https://www.mathworks.com/help/matlab/matlab_oop/indexed-assignment.html
specifically:
"If A does not exist before you execute the assignment statement, then MATLAB initializes the five array elements that come before A(2,3) with default objects of class B. "
So as said in comment #9, this default object is 0.0 for floating point numbers, 0 or false for logical, etc. but it may not be 'null' for other classes. I've never messed with classes, but I assume a 'default object' is defined when one is created. Is there any case to verify that Octave follows that behavior if the default is not a 'null'?
|
Fri 03 Feb 2017 03:48:18 PM UTC, comment #12:
Everything about the assignment behavior has been confirmed on Matlab. Thus, to finish this off, we need someone to propose language for the documentation that explains how Octave/Matlab fill in the "empty" values of a vector/matrix when assigning to the end value.
The place for this is Section 8.6 "Assignment Expressions" in the file doc/interpreter/expr.txi.
|
Thu 02 Feb 2017 05:54:45 PM UTC, comment #11:
As to comment #5, ML r2017a does:
... and as to comment #8 and comment #9,
|
Wed 01 Feb 2017 06:41:36 PM UTC, comment #10:
Yes I also checked that bool matrix where padded with false.
|
Wed 01 Feb 2017 06:32:44 PM UTC, comment #9:
Per comment #8, that is the correct behavior, although someone could double check in matlab.
When you do
the equivalent pseudo-code is
where NULL is appropriate to whatever the underlying class is. For doubles, NULL is 0.0. For logical types, NULL is 0 or false.
|
Wed 01 Feb 2017 06:13:53 PM UTC, comment #8:
By the way, a(3)=true performs padding with false.
I made a mistake with objects:
There seems no padding.. just null....
|
Wed 01 Feb 2017 04:42:23 PM UTC, comment #7:
Gag I'm sure those reports will start rolling in soon.
|
Wed 01 Feb 2017 04:33:27 PM UTC, comment #6:
I will make the bold prediction that it won't be long before we start seeing bug reports about this incompatibility...
|
Wed 01 Feb 2017 04:32:28 PM UTC, comment #5:
I guess that in current versions of Matlab, line returns some kind of graphics object. In earlier versions it just returned a graphics handle, which was simply a double precision number, the same as Octave does now.
|
Wed 01 Feb 2017 04:27:19 PM UTC, comment #4:
I tested with line objects and the logic seams to be the same:
They pad with "GraphicsPlaceholder", the equivalent of a 0 for double.
|
Wed 01 Feb 2017 04:06:54 PM UTC, comment #3:
I also don't know how classes behave, but this is Matlab compatible behavior that we need to keep, and should document for clarity.
|
Wed 01 Feb 2017 02:58:10 PM UTC, comment #2:
I think the "Assignment Expressions" section is the right place to explain this behavior.
|
Wed 01 Feb 2017 01:52:15 PM UTC, comment #1:
Hi,
I didn't check how classes behave in ML (2016a), but at list Matrix behave exactly the same. Could you look at the manual and find where and how to document this behavior?
|
Wed 01 Feb 2017 12:03:13 PM UTC, original submission:
If you have an undefined variable a
settig a(3)=4 yields a vector padded with 0's.
Likewise for a(3,4)=true.
I also have the impression, that arrays of objects
behave a little the same:
Assume pn is a class and a constructor,
a(3)=pn(4) seems to perform padding with pn().
If so, this should be documented.
I do not know how matlab acts in this case.. did not find docs.
|