Thu 25 Aug 2016 11:41:30 PM UTC, comment #7:
Mike, I pushed a changeset here:
http://hg.savannah.gnu.org/hgweb/octave/rev/6cbbd550aa91
Sorry, I should have posted here that I was going to do it.
|
Thu 25 Aug 2016 11:38:17 PM UTC, comment #6:
Ok, sounds good. I'll rework my change to use is_zero_by_zero and push that shortly.
|
Thu 25 Aug 2016 11:35:00 PM UTC, comment #5:
yes only a 2d 0x0 matrix works in subsasgn, anything else errors including zeros(0,1) or zeros(0,0,0) or zeros(0,0,1,0).
You're right it makes sense to have a consistent way to delete from arrays using the literal [], for both builtin numeric/struct/cell types and array of class objects.
|
Thu 25 Aug 2016 12:30:51 AM UTC, comment #4:
I'm pretty sure this is a bit of a kluge to allow "x(idx) = []" to work for classes the same way as for ordinary built-in objects. For objects, the syntax is converted to a call to the subsasgn method for the class (if it is defined). Because [] is an empty double array, it makes sense to limit it to this type, and I assume, also a 0x0 array, not 0x1, or any other shape of empty array. But because the literal [] empty array loses its special status when it is assigned to a variable or passed to a function, subsasgn must accept "zeros(0,0)" as well. And, because subsasgn can work for built-in types, it must also work this way for them.
Amro, can you verify that zeros(0,0) works but zeros(0,0,1,0) does not?
Mike, your patch should be fine, but if I'm right about the 0x0 thing, then it should probably use is_zero_by_zero instead of is_empty. I just fixed is_zero_by_zero so that it requires exactly two dimensions and that both are 0.
|
Wed 24 Aug 2016 09:05:34 PM UTC, comment #3:
Funny enough, only double-type empty-matrix is accepted by subsasgn, even when the array is not double itself!
same thing with zeros(0,0,'single') as opposed to zeros(0,0).
|
Tue 23 Aug 2016 10:34:05 PM UTC, comment #2:
The following change makes the samples you've shown here compatible with Matlab:
Does subsasgn also work when the argument is single([]) or does it have to be double([])?
|
Tue 23 Aug 2016 02:52:43 PM UTC, comment #1:
The token "[]" is handled as the special type "null_matrix" in Octave, which looks like it is only handled specially for assignment statements in the language. Once it is assigned to something else or passed into a function like double(), it is no longer a null_matrix.
Maybe in the function subsasgn, any empty matrix argument could be recognized and replaced with a null_matrix when the underlying subsasgn object method is called.
|
Tue 23 Aug 2016 10:57:05 AM UTC, original submission:
In another thread, @jwe mentioned in a comment how "[]" is treated differently when deleting elements from an array.
I did a quick test and I found another minor case where behavior is different between MATLAB and Octave. I didn't wanna clutter the original thread with unrelated discussion, so I'm reporting it here as a new bug (feel free to mark it as low priority).
Here is an example (tested in Octave 4.0 and MATLAB R2016a, both on Windows):
So calling "subsasgn" with "nil" seems to work in MATLAB, even though the equivalent syntax with direct assignment doesn't... Go figure :)
|