bugGNU Octave - Bugs: bug #40576, Assignment to Cell Array of...

 
 

bug #40576: Assignment to Cell Array of Structure Fields Gives invalid assignment Error

Submitter:  Matt <seventhunders>
Submitted:  Thu 14 Nov 2013 04:55:08 AM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Matt Open/Closed:  * Closed
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sun 20 Nov 2016 06:11:56 PM UTC, comment #4: 

This has been fixed in 4.2.0.  Upgrade to the latest stable version of Octave to see the fix.

Rik <rik5>
Group administrator
Thu 14 Nov 2013 02:22:48 PM UTC, comment #3: 

I see the same thing with 3.6.4 and the development version. Requires a cell array with ndims > 2, a trailing singleton dimension, and assignment to a field of a structure contained in that cell array.


x = cell (1, 1);
ndims (x)
ans =  2  # no problem here

x = cell (3, 2, 2);
ndims (x)
ans =  3
x{1,1,1}.y = 0;  # no error

x = cell (3, 2, 1);
ndims (x)
ans =  2
x{1,1,1}.y = 0;  # error
x{1,1,1} = 0;    # no error

x = cell (5, 5, 5, 1, 1, 1);
ndims (x)
ans =  3


Mike Miller <mtmiller>
Group Member
Thu 14 Nov 2013 06:57:31 AM UTC, comment #2: 

Actually it is a bug and here's why.  The cell array pcUlBuff was created with the statement
pcUlBuf=cell(3,numEn,numCfgs);

But with numEn = 2 and numCfgs = 1.  octave auto squeezes this to a 3 x 2 cell array.  But the code expects to be able to index into the third dimension, otherwise you will have to have guards for special of trailing 1's in your dimensions.  Something which Matlab does not require.  Thanks for the observation though because it now allows for a pathetically simple test case.

z321 = cell(3,2,1) ;
a.bin = 4 ;
z321{1,1,1} = a ;
z321{1,1,1}.bin = 5 ;


Doesn't require the save file now. Intuitively one would expect that if you create an array,  even if a dimension has length one, that you should be able to index that dimension. 

The one dimension would naturally occur as edge cases for parameter variations and is often unavoidable.

By the way, it appears that the bug requires the cell array point to a structure with fields for some reason, in  order to manifest.

Matt <seventhunders>
Thu 14 Nov 2013 06:29:54 AM UTC, comment #1: 

I'm not sure the problem is quite so terrible.  The sample code is indexing outside the cell array.  Perhaps for compatibility Octave should be squeezing out the final singleton dimension, but in the mean time you can get the code to work by staying within your array.


load cellasbug
whos
Variables in the current scope:

   Attr Name         Size                     Bytes  Class
   ==== ====         ====                     =====  =====
        pcUlBuf      3x2                     101184  cell

Total is 6 elements using 101184 bytes
pcUlBuf{1,1}.bins = 2 * pcUlBuf{1,1}.bins;  # succeeds
pcUlBuf{1,1}.bins = 2
pcUlBuf =
{
  [1,1] =

    scalar structure containing the fields:

      bins =  2
      subbBanks =

         0.020469   0.020469
         0.020469   0.020469
...
...


Rik <rik5>
Group administrator
Thu 14 Nov 2013 04:55:08 AM UTC, original submission:  

This is a pretty nasty little bug that breaks compatibility with Matlab.  Basically for fairly complex cell arrays that contain structures, it may fail to assign fields of those structures.

Consider the following code snippet.  (Requires loading saved cell array file cellassbug)


load cellassbug
% error: invalid assignment to cs-list outside multiple assignment
pcUlBuf{1,1,1}.bins = 2 * pcUlBuf{1,1,1}.bins ;
% actually any assignment to members of the cell array struct now fails
% e.g.
pcUlBuf{1,1,1}.bins = 2 ;


Running this with the provided saved file yields the error,
error: invalid assignment to cs-list outside multiple assignment

Matlab has no problem with this, and I don't understand why octave should have issues with it either.

Matt <seventhunders>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #29617:  cellassbug added by seventhunders (248KiB - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by seventhunders (Submitted the item)
  • -email is unavailable- added by seventhunders
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-11-20 rik5 StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2013-11-14 mtmiller StatusNone Confirmed
        Release3.6.4 dev
    2013-11-14 seventhunders Attached File- Added cellassbug, #29617
        Carbon-Copy- Added -email is unavailable-

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code