bugGNU Octave - Bugs: bug #59191, Using (end+1) on an empty matrix...

 
 

bug #59191: Using (end+1) on an empty matrix refers causes unexpected padding with zeros

Submitter:  None
Submitted:  Sun 27 Sep 2020 02:00:12 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Inaccurate Result
Status:  Invalid / Not an Octave Bug Assigned to:  None
Originator Name:  Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * dev
Operating System:  * GNU/Linux Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sun 27 Sep 2020 06:01:48 PM UTC, comment #1: 

I don't think this is a bug but rather how matrix indexing works in Octave.

(Trailing) singleton dimensions have a size of 1:

>> a = ones (2, 3);
>> [sz1, sz2, sz3] = size (a)
sz1 = 2
sz2 = 3
sz3 = 1


So `end+1` for the third dimension of `a` is 2.

Unassigned values are always initialized with 0:

>> clear b;
>> b(2,3) = 1
b =

   0   0   0
   0   0   1


Closing as invalid.


Markus Mützel <mmuetzel>
Group administrator
Sun 27 Sep 2020 02:00:12 PM UTC, original submission:  

Octave version 7.0.0 with hg id 901a92f45ff0 on 64-bit Linux

When augmenting an array by using (end+1) as the subscript on an lvalue, it works properly for one or two dimensions, but for three or more dimensions it causes the array to be unexpectedly pre-padded with an extra layer of zeros. It appears that (end+1) for an empty matrix refers to subscript value 1 for one and two dimensions, but subscript value 2 for three or more dimensions.

Once this behavior is known, it can certainly be worked around by the user. It is being reported in case the behavior was not intended.


octave:7> lst = []; lst(end+1,:) = pi(1,4), size(lst)
lst =
   3.1416   3.1416   3.1416   3.1416

ans =
   1   4

octave:8> lst = []; lst(:,end+1) = pi(1,4), size(lst)
lst =
   3.1416
   3.1416
   3.1416
   3.1416

ans =
   4   1

octave:9> lst = []; lst(:,:,end+1) = pi(4,4), size(lst)
lst =
ans(:,:,1) =
   0   0   0   0
   0   0   0   0
   0   0   0   0
   0   0   0   0
ans(:,:,2) =
   3.1416   3.1416   3.1416   3.1416
   3.1416   3.1416   3.1416   3.1416
   3.1416   3.1416   3.1416   3.1416
   3.1416   3.1416   3.1416   3.1416

ans =
   4   4   2
octave:10> lst = []; lst(:,:,:,end+1) = pi(4,4), size(lst)
lst =
ans(:,:,1,1) =
   0   0   0   0
   0   0   0   0
   0   0   0   0
   0   0   0   0
ans(:,:,1,2) =
   3.1416   3.1416   3.1416   3.1416
   3.1416   3.1416   3.1416   3.1416
   3.1416   3.1416   3.1416   3.1416
   3.1416   3.1416   3.1416   3.1416

ans =
   4   4   1   2


Anonymous

 

(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 mmuetzel (Posted a comment)
  •  

    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 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-09-27 mmuetzel StatusNone Invalid / Not an Octave Bug
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code