bugGNU Octave - Bugs: bug #54966, Error when assigning array to an...

 
 

bug #54966: Error when assigning array to an object implementing subsasgn() subscripted using "{}"

Submitted by:  Martynas <mpata>
Submitted on:  Mon 05 Nov 2018 09:55:15 PM UTC  
 
Category:  Interpreter Severity:  1 - Wish
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Confirmed Assigned to:  None
Originator Name:  Open/Closed:  Open
Release:  dev Operating System:  Any

Add a New Comment (Rich Markup)
   

You are not logged in

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

 

Thu 21 Feb 2019 02:20:55 PM UTC, comment #2:

I pushed an overhauled classdef test to stable addressing this issue with some xtests:

https://hg.savannah.gnu.org/hgweb/octave/rev/ad71c8d87cff

This is no fix. The curly braces '{}' assignment does not work yet, but we have a test that works in Matlab, when it is fixed.

Kai Torben Ohlhus <siko1056>
Project Member
Tue 12 Feb 2019 12:16:13 PM UTC, comment #1:

This problem is still present in the current stable version 5.0.91.

While investigating the problem, I found a hack for 4.4.1 and 5.0.91, which of course is no solution at all.  Modify your exampleclass by adding a numel method which only returns "1":

classdef exampleclass

  properties
    b = {1, 2};
  end

  methods
    function ret = numel (obj)
      ret = 1;
    end

    function varargout = subsasgn (obj, idx, rhs)
      disp (idx)
      switch idx(1).type
        case '()'
          obj.b = subsasgn (obj.b, idx, rhs);
          varargout = {obj};
        case '{}'
          idx(1).type = '()';
          obj.b = subsasgn (obj.b, idx, rhs);
          varargout = {obj};
        otherwise
          varargout = {builtin('subsasgn', obj, idx, rhs)};
      end
    end
  end

end

Some explanation:

The error message you are facing is called

err_invalid_structure_assignment ()

from "libinterp/corefcn/errwarn.h".  The only occurrence of this message is libinterp/parse-tree/pt-eval.cc (line 2678) [1] when the left-hand side of the assignment is checked for "numel != 1".

I think there must be added an exception for objects, but it seems to be useful for structs.  At the moment I cannot come up with a proper solution to this.

[1] https://hg.savannah.gnu.org/hgweb/octave/file/7b9a5ab8350f/libinterp/parse-tree/pt-eval.cc#l2678

Kai Torben Ohlhus <siko1056>
Project Member
Mon 05 Nov 2018 09:55:15 PM UTC, original submission:

GNU Octave seems to give an error message when assigning an array with several elements to an object implementing subsasgn() method subscripted using curled braces.

Let's say we have a class (implementing the same assignment for "()" and "{}"):

classdef exampleclass

properties
  b = {1, 2};
end

methods
  function [obj] = exampleclass ()
  end

  function [varargout] = subsasgn (obj, IDX, RHS)
    switch IDX(1).type
      case '()'
        IDXcell = IDX;
        IDXcell(1).type = '()';
        [obj.b] = subsasgn (obj.b, IDXcell, RHS);
        varargout = {obj};
      case '{}'
        IDXcell = IDX;
        IDXcell(1).type = '()';
        [obj.b] = subsasgn (obj.b, IDXcell, RHS);
        varargout = {obj};
      otherwise
        [varargout] = {builtin('subsasgn', obj, IDX, RHS)};
    end
  end
end

end

And run a script trying out different assignments:

[ex] = exampleclass();

ex(1) = {2};
ex.b
ex{1} = {3};
ex.b
ex(1:2) = {2, 3};
ex.b
ex{1:2} = {3, 4};
ex.b

In GNU Octave the last assignment (but none of the previous ones) results in error message (path removed):

ans =
{
  [1,1] =  2
  [1,2] =  2
}

ans =
{
  [1,1] =  3
  [1,2] =  2
}

ans =
{
  [1,1] =  2
  [1,2] =  3
}

error: invalid dot name structure assignment because the structure array is empty.  Specify a subscript on the structure array to resolve.
error: called from
    examplescript at line 9 column 8
stopped in ...\examplescript.m at line 9
9: ex{1:2} = {3, 4};
                        ^

In Matlab assignments do not fail:

ans =

  1×2 cell array

    {[2]}    {[2]}


ans =

  1×2 cell array

    {[3]}    {[2]}


ans =

  1×2 cell array

    {[2]}    {[3]}


ans =

  1×2 cell array

    {[3]}    {[4]}

Martynas <mpata>

 

(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

 

Carbon-Copy List
  • -email is unavailable- added by siko1056 (Updated the item)
  • -email is unavailable- added by mpata (Submitted the item)
  •  

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

    Only project members can vote.

     

     

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-02-26 mtmiller Severity3 - Normal => 1 - Wish
        Release5.0.91 => dev
    2019-02-12 siko1056 StatusNone => Confirmed
        Release4.4.1 => 5.0.91
        Operating SystemMicrosoft Windows => Any

    Back to the top


    Powered by Savane 3.4