octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #56856] Matlab calls class subsasgn method wit


From: JD
Subject: [Octave-bug-tracker] [bug #56856] Matlab calls class subsasgn method with array of double instead of class type
Date: Wed, 11 Nov 2020 16:54:48 -0500 (EST)
User-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36

Follow-up Comment #10, bug #56856 (project octave):

Looking back at this question, I notice that:

  1. The following code

y = subsasgn (zeros(1, 10), substruct('()', {10}), inputParser())

not only produces an error in Matlab, but also in Octave 6.0.92 (using this
version throughout this message), namely:

error: operator =: no conversion for assignment of 'object' to indexed
'matrix'

so this looks as expected, and it shouldn't be an argument against fixing this
issue.

  2. A class object should not exist without having been constructed.
Currently, Octave is doing exactly the opposite: when calling

x(10) = a

with 'a' of type 'test' an 'x' undeclared (i.e. of no defined type yet, or as
left by the command 'clear x'), Octave assigns the type 'test' to the target
variable 'x', but does not actually construct this object(!). Therefore, 'x'
is in an undefined state. It looks _like_ a 'test' object, but actually it is
not since its properties have not been initialized. Therefore it cannot be
manipulated in any meaningful way. Somehow this is the very essence of this
bug. And it is certainly quite understandable that it would produce some
problems. I don't see a reason why this should not be fixed.

  3. The way Matlab solves this issue (see [comment #4 comment #4:] below) is
by giving to unspecified variable 'x' the value of an empty array '[]'. This
may seem arbitrary, but it has at least two advantages:
    a. Contrary to the current behavior of Octave, all variables are always in
a well-defined state. In the code of the function 'subsasgn', 'x' is a
variable that can be manipulated. This is just the same as would occur if the
variable 'x' had been initialized as an empty object with 'x=[]', so we can
also expect a meaningful behavior of the 'subsasgn' function. Indeed, the
empty array is a valid variable value.
    b. This avoid requiring Octave to rely on the type or dimension of the
right hand side to _guess_ the type that the lhs variable should have. This
will ultimately be decided by the 'subsasgn' function anyway. Even more so
when a 'subsasgn' function implementation is part of the class description
provided by the user.

In this respect, maybe a more accurate title for this issue would be
'Undefined variables are represented by empty array of double in Matlab to
ensure they always are well-defined objects'.

Concretely, I'ld suggest that whenever Octave needs to create a new variable
that doesn't exist yet, because it needs to provide it in some function call
for instance, it would assigns the value '[]' (i.e. empty array of double).
This would correspond to what Matlab does, would be highly predictable (in
particular would avoid any illdefined states) and would allow the user to deal
with the situation.

    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?56856>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]