bugGNU Octave - Bugs: bug #48867, delete elements from array with...

 
 

bug #48867: delete elements from array with indirect empty matrix

Submitted by:  Amro <amro_octave>
Submitted on:  Tue 23 Aug 2016 10:57:05 AM UTC  
 
Category: InterpreterSeverity: 1 - Wish
Priority: 3 - LowItem Group: WTF, Matlab?!?
Status: FixedAssigned to: Mike Miller <mtmiller>
Originator Name: Open/Closed: Closed
Release: devOperating System: Any

Add a New Comment(Rich Markup)
   

You are not logged in

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

 

(Jump to the original submission Jump to the original submission)

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.

John W. Eaton <jwe>
Project Administrator
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.

Mike Miller <mtmiller>
Project AdministratorIn charge of this item.
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.

Amro <amro_octave>
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.

John W. Eaton <jwe>
Project Administrator
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).

Amro <amro_octave>
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([])?

Mike Miller <mtmiller>
Project AdministratorIn charge of this item.
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.

Mike Miller <mtmiller>
Project AdministratorIn charge of this item.
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 :)

Amro <amro_octave>

 

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

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by jwe (Posted a comment)
  • -unavailable- added by mtmiller (Posted a comment)
  • -unavailable- added by amro_octave (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 8 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Thu 25 Aug 2016 11:41:40 PM UTCjweStatusReady For Test=>Fixed
    Thu 25 Aug 2016 11:41:30 PM UTCjweStatusPatch Submitted=>Ready For Test
      Open/ClosedOpen=>Closed
    Thu 25 Aug 2016 11:38:17 PM UTCmtmillerAssigned toNone=>mtmiller
    Tue 23 Aug 2016 10:34:05 PM UTCmtmillerStatusNone=>Patch Submitted
    Tue 23 Aug 2016 02:52:47 PM UTCmtmillerSeverity3 - Normal=>1 - Wish
    Tue 23 Aug 2016 02:52:43 PM UTCmtmillerPriority5 - Normal=>3 - Low
      Release4.0.3=>dev

    Back to the top


    Powered by Savane 3.1-cleanup1