bugGNU Octave - Bugs: bug #46571, classdef numel method not...

 
 

bug #46571: classdef numel method not consulted for cell-indexed assignment

Submitted by:  Stéphane Adjemian <step4n>
Submitted on:  Mon 30 Nov 2015 01:38:57 PM UTC  
 
Category: InterpreterSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Incorrect Result
Status: ConfirmedAssigned to: None
Originator Name: Stéphane AdjemianOpen/Closed: Open
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.

 

Fri 24 Nov 2017 08:18:16 PM UTC, comment #4:

Thanks to the analysis done by Mike Miller, I was able to craft a patch for this issue (in attachment).

It adds the octave_classdef::numel method, tying it to the user override method.

The patch applies on the stable branch. I verified that it introduces no regression in the testsuite (I also tested it on the default branch).

(file #42472)

Sébastien Villemot <svillemot>
Fri 05 Aug 2016 12:46:57 AM UTC, comment #3:

Dug into this a bit further, and confirmed that the error is that the numel method is not consulted when Octave is trying to figure out how many values need to be on the left and right of the assignment operator in an indexing expression. Since the inconsistency is detected solely through calling the numel method, the class subsasgn is never even called.

Octave expects types to define a numel function that returns the appropriate number of elements that would be indexed given an indexing argument. This is done correctly for old-style classes but not classdef classes.

Therefore, as assignment like `a{'v1'} = ones (10, 1)` is assumed to be assigning to 2 elements of a cell-array-like thing.

Mike Miller <mtmiller>
Project Administrator
Tue 02 Aug 2016 07:53:09 AM UTC, comment #2:

Actually I think the error is occurring in the parser, but I am not sure why it is triggered for new-style classes but not old-style classes.

With just a trivial class definition / constructor and no other methods defined, this error occurs with classdef:

but not if the class is a struct-based old-style class:

In the first case, the error is caught when the parser is evaluating the assignment expression. In the second case, the error is only because there is no custom aubsasgn method defined.

You're right that it has something to do with interpreting the string index as an array of multiple indices, but I'm not clear at the moment why it's not a problem when the old class definition style is used.

Mike Miller <mtmiller>
Project Administrator
Fri 15 Apr 2016 12:18:49 AM UTC, comment #1:

If the code doesn't enter @myclass/subsasgn, it will be interpreting 'v1' as 1x2 array, which is why it gets confused about a cs-list.

The fact that it "works" with just 'v' is probably a result of the fact that the custom subsasgn does the same thing as the default subsasgn in that case.

Lachlan Andrew <lachlan>
Project Member
Mon 30 Nov 2015 01:38:57 PM UTC, original submission:

Calls to the subsasgn are not working with the new class syntax. In the attached files I provide two implementations of the same class with the old and new (ie using classdef) interfaces.

With the new interface the following code :

returns

while the same code returns the expected results with the old oop syntax. Note also that both interfaces produce the same expected results with Matlab 2015b. Debugging the code reveals that we never enter the @myclass/subsasgn function.

Note also that the problem does not pop up if the length of the string used as an index is equal to one, ie:

produces the expected result.

Stéphane Adjemian <step4n>

 

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

Attach File(s):
   
   
Comment:
   

Attached Files
file #42472:  bug46571.patch added by svillemot (2KiB - text/x-patch)
file #35596:  new-syntax.tar added by step4n (10KiB - application/x-tar - Two implementations of the same class)
file #35597:  old-syntax.tar added by step4n (10KiB - application/x-tar - Two implementations of the same class)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by svillemot (Updated the item)
  • -unavailable- added by mtmiller (Posted a comment)
  • -unavailable- added by lachlan (Posted a comment)
  • -unavailable- added by step4n (Submitted the item)
  • -unavailable- added by step4n
  •  

    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
    Fri 24 Nov 2017 08:18:16 PM UTCsvillemotAttached File-=>Added bug46571.patch, #42472
    Fri 05 Aug 2016 12:46:57 AM UTCmtmillerSummaryInconsistency between old and new oop syntax (wrt subsasgn)=>classdef numel method not consulted for cell-indexed assignment
    Tue 02 Aug 2016 07:53:09 AM UTCmtmillerStatusNone=>Confirmed
      Release4.0.0=>dev
    Fri 15 Apr 2016 12:18:48 AM UTClachlanItem GroupNone=>Incorrect Result
    Mon 30 Nov 2015 01:38:57 PM UTCstep4nAttached File-=>Added new-syntax.tar, #35596
      Attached File-=>Added old-syntax.tar, #35597
      Carbon-Copy-=>Added step4n

    Back to the top


    Powered by Savane 3.1-cleanup1