bugGNU Octave - Bugs: bug #50202, automatic padding: a(3)=4

 
 

bug #50202: automatic padding: a(3)=4

Submitted by:  Ernst Reissner <ernstreissner>
Submitted on:  Wed 01 Feb 2017 12:03:13 PM UTC  
 
Category: DocumentationSeverity: 3 - Normal
Priority: 5 - NormalItem Group: None
Status: ConfirmedAssigned to: None
Originator Name: Open/Closed: Open
Release: 4.2.0Operating System: Any

Add a New Comment(Rich Markup)
   

You are not logged in

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

 

(Jump to the original submission Jump to the original submission)

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>
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>
Project Administrator
Thu 02 Feb 2017 05:54:45 PM UTC, comment #11:

As to comment #5, ML r2017a does:

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

Philip Nienhuis <philipnienhuis>
Project 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>
Project 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

the equivalent pseudo-code is

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>
Project 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>
Project 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>
Project 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>
Project 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:

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

Pantxo Diribarne <pantxo>
Project 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>
Project 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>
Project 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>
Project 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 File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by cbm (Posted a comment)
  • -unavailable- added by nrjank (Posted a comment)
  • -unavailable- added by rik5 (Posted a comment)
  • -unavailable- added by jwe (Posted a comment)
  • -unavailable- added by pantxo (Posted a comment)
  • -unavailable- added by ernstreissner (Submitted the item)
  • -unavailable- added by ernstreissner
  •  

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

    Date Changed By Updated Field Previous Value => Replaced By
    Fri 03 Feb 2017 03:48:18 PM UTCrik5StatusNone=>Confirmed
    Wed 01 Feb 2017 12:03:13 PM UTCernstreissnerCarbon-Copy-=>Added -unavailable-

    Back to the top


    Powered by Savane 3.1-cleanup1