bugGNU Octave - Bugs: bug #50202, automatic padding of null values...

 
 

bug #50202: automatic padding of null values for assignments outside current object size

Submitter:  Ernst Reissner <ernstreissner>
Submitted:  Wed 01 Feb 2017 12:03:13 PM UTC
   
 
Category:  Documentation Severity:  3 - Normal
Priority:  5 - Normal Item Group:  None
Status:  Ready For Test Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * 4.2.0 Operating System:  * Any
Fixed Release:  None Planned Release:  9.1.0
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Tue 13 Feb 2024 05:30:46 PM UTC, comment #18: 

pushed a documentation update to stable for the Assignment Expressions section. Adds description and examples of the array padding behavior. Also added some comments & an example on array shape after deletion.

https://hg.savannah.gnu.org/hgweb/octave/rev/6183b28cc423

Marking as ready for test for now in case anyone wants to review the text / makes sure i didn't miss or mis-state anything.

Nicholas Jankowski <nrjank>
Group Member
Tue 13 Feb 2024 02:22:18 PM UTC, comment #17: 

Actually, i seem to recall a recent discussion that we probably should expect arrays of classes to fail unless they implement their own subsasgn to handle it, because Octave's current implementation cannot create arrays of general class objects.

I'll look at adding some text to the Assignment Expressions page and just note the general limitation on arraying classes.

Nicholas Jankowski <nrjank>
Group Member
Tue 13 Feb 2024 02:07:15 PM UTC, comment #16: 

looking at this doc case, just adding that @cbm was correct that classes need to deal with this themselves, but that may be the case even if they don't overload subsasgn.  e.g., octave's inputParser does not have a subsref or subsasgn method, and:



>> b = inputParser()
b =

inputParser object with properties:

   FunctionName    : ""
   CaseSensitive   : false
   KeepUnmatched   : false
   PartialMatching : true
   StructExpand    : true

Defined parameters:

   {}

>> b(5)= inputParser()
error: Invalid resizing operation or ambiguous assignment to an out-of-bounds array eleme
nt


whereas matlab2023b:


>> b = inputParser()

b =

  inputParser with properties:

       FunctionName: ''
      CaseSensitive: 0
      KeepUnmatched: 0
    PartialMatching: 1
       StructExpand: 1
         Parameters: {1×0 cell}
            Results: [1×1 struct]
          Unmatched: [1×1 struct]
      UsingDefaults: {1×0 cell}

>> b(4) = inputParser()

b =

  1×4 inputParser array with properties:

    FunctionName
    CaseSensitive
    KeepUnmatched
    PartialMatching
    StructExpand
    Parameters
    Results
    Unmatched
    UsingDefaults


Nicholas Jankowski <nrjank>
Group Member
Tue 14 Feb 2017 10:33:40 AM UTC, comment #15: 

ok, but if this is the case, this should be explicitly documented
as is documented that constructor with no argument shall return the default object value.
One should say that subsasn
shall use the default value for padding.

Ernst Reissner <ernstreissner>
Mon 06 Feb 2017 07:58:32 PM UTC, comment #14: 


> but I assume a 'default object' is defined when one is created


Yes, "Ideally, even when the constructor is called with no arguments it should return a valid object." https://www.gnu.org/software/octave/doc/interpreter/Creating-a-Class.html
(I seem to remember this is also needed to support save/load).

If the class overrides "subsasn" then it may need to deal with this padding issue by itself.  I've just [patched Symbolic to do so](https://github.com/cbm755/octsympy/pull/760).

Colin Macdonald <cbm>
Sun 05 Feb 2017 06:57:59 PM UTC, comment #13: 

I believe the following Matlab documentation page describes how it handles indexed assignment, including what it does if the object doesn't exist:

https://www.mathworks.com/help/matlab/matlab_oop/indexed-assignment.html

specifically:

"If A does not exist before you execute the assignment statement, then MATLAB initializes the five array elements that come before A(2,3) with default objects of class B. "

So as said in comment #9, this default object is 0.0 for floating point numbers, 0 or false for logical, etc. but it may not be 'null' for other classes. I've never messed with classes, but I assume a 'default object' is defined when one is created. Is there any case to verify that Octave follows that behavior if the default is not a 'null'?

Nicholas Jankowski <nrjank>
Group Member
Fri 03 Feb 2017 03:48:18 PM UTC, comment #12: 

Everything about the assignment behavior has been confirmed on Matlab.  Thus, to finish this off, we need someone to propose language for the documentation that explains how Octave/Matlab fill in the "empty" values of a vector/matrix when assigning to the end value.

The place for this is Section 8.6 "Assignment Expressions" in the file doc/interpreter/expr.txi.

Rik <rik5>
Group administrator
Thu 02 Feb 2017 05:54:45 PM UTC, comment #11: 

As to comment #5, ML r2017a does:

>> format compact
>> h = line ([0 1], [2 3])
h =
  Line with properties:

              Color: [0 0.4470 0.7410]
          LineStyle: '-'
          LineWidth: 0.5000
             Marker: 'none'
         MarkerSize: 6
    MarkerFaceColor: 'none'
              XData: [0 1]
              YData: [2 3]
              ZData: [1×0 double]

  Show all properties
>> ishandle (h)
ans =
  logical
   1
>>



... and as to comment #8 and comment #9,

>> a(3) = true
a =
  1×3 logical array
   0   0   1
>>



Philip Nienhuis <philipnienhuis>
Group Member
Wed 01 Feb 2017 06:41:36 PM UTC, comment #10: 

Yes I also checked that bool matrix where padded with false.


Pantxo Diribarne <pantxo>
Group Member
Wed 01 Feb 2017 06:32:44 PM UTC, comment #9: 

Per comment #8, that is the correct behavior, although someone could double check in matlab.

When you do


x(idx) = val;


the equivalent pseudo-code is


x(1:idx-1) = NULL;
x(idx) = val;


where NULL is appropriate to whatever the underlying class is.  For doubles, NULL is 0.0.  For logical types, NULL is 0 or false.


Rik <rik5>
Group administrator
Wed 01 Feb 2017 06:13:53 PM UTC, comment #8: 

By the way, a(3)=true performs padding with false.

I made a mistake with objects:
There seems no padding.. just null....

Ernst Reissner <ernstreissner>
Wed 01 Feb 2017 04:42:23 PM UTC, comment #7: 

Gag  I'm sure those reports will start rolling in soon.

Rik <rik5>
Group administrator
Wed 01 Feb 2017 04:33:27 PM UTC, comment #6: 

I will make the bold prediction that it won't be long before we start seeing bug reports about this incompatibility...

John W. Eaton <jwe>
Group administrator
Wed 01 Feb 2017 04:32:28 PM UTC, comment #5: 

I guess that in current versions of Matlab, line returns some kind of graphics object.  In earlier versions it just returned a graphics handle, which was simply a double precision number, the same as Octave does now.

John W. Eaton <jwe>
Group administrator
Wed 01 Feb 2017 04:27:19 PM UTC, comment #4: 

I tested with line objects and the logic seams to be the same:


a(2) = line ();
>> a

a =

  1x2 graphics array:

    GraphicsPlaceholder    Line

>> a(1)

ans =

  GraphicsPlaceholder with no properties.

>> a(2)

ans =

  Line with properties:

              Color: [0 0 0]
          LineStyle: '-'
          LineWidth: 0.5000
             Marker: 'none'
         MarkerSize: 6
    MarkerFaceColor: 'none'
              XData: [0 1]
              YData: [0 1]
              ZData: [1x0 double]

  Show all properties

>>


They pad with "GraphicsPlaceholder", the equivalent of a 0 for double.

Pantxo Diribarne <pantxo>
Group Member
Wed 01 Feb 2017 04:06:54 PM UTC, comment #3: 

I also don't know how classes behave, but this is Matlab compatible behavior that we need to keep, and should document for clarity.

Rik <rik5>
Group administrator
Wed 01 Feb 2017 02:58:10 PM UTC, comment #2: 

I think the "Assignment Expressions" section is the right place to explain this behavior.

John W. Eaton <jwe>
Group administrator
Wed 01 Feb 2017 01:52:15 PM UTC, comment #1: 

Hi,

I didn't check how classes behave in ML (2016a), but at list Matrix behave exactly the same. Could you look at the manual and find where and how to document this behavior?

Pantxo Diribarne <pantxo>
Group Member
Wed 01 Feb 2017 12:03:13 PM UTC, original submission:  

If you have an undefined variable a
settig a(3)=4 yields a vector padded with 0's.
Likewise for a(3,4)=true.

I also have the impression, that arrays of objects
behave a little the same:
Assume pn is a class and a constructor,
a(3)=pn(4) seems to perform padding with pn().

If so, this should be documented.
I do not know how matlab acts in this case.. did not find docs.

Ernst Reissner <ernstreissner>

 

(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 cbm (Posted a comment)
  • -email is unavailable- added by nrjank (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by pantxo (Posted a comment)
  • -email is unavailable- added by ernstreissner (Submitted the item)
  • -email is unavailable- added by ernstreissner
  •  

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

    Date Changed by Updated Field Previous Value => Replaced by
    2024-02-13 nrjank StatusConfirmed Ready For Test
        Planned ReleaseNone 9.1.0
        Summaryautomatic padding: a(3)=4 automatic padding of null values for assignments outside current object size
    2017-02-03 rik5 StatusNone Confirmed
    2017-02-01 ernstreissner Carbon-Copy- Added -email is unavailable-

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code