bugGNU Octave - Bugs: bug #46892, subsref for OO @class failed to be...

 
 

bug #46892: subsref for OO @class failed to be called within method function.

Submitter:  Rik <rik5>
Submitted:  Wed 13 Jan 2016 11:55:36 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 14 Jan 2016 04:16:44 PM UTC, comment #3: 

@Oliver: Thanks for pointing out the futility of having indexing operators call subsref within a method function itself.  I only came across some of these issues because I overhauled the documentation on Object Oriented programming (http://hg.savannah.gnu.org/hgweb/octave/rev/220506787b93) and found that some of the code would not work.

In this case, the clearer solution was to avoid subsref entirely and just call polyval.  See this cset http://hg.savannah.gnu.org/hgweb/octave/rev/9b3149cd486b.

Rik <rik5>
Group administrator
Thu 14 Jan 2016 06:34:32 AM UTC, comment #2: 

… as always I have forgotten the curly braces.

````
idx = struct ("type", "()", "subs", {x})
plot (x, subsref (p, idx), varargin{:});
````

Oliver Heimlich <oheim>
Thu 14 Jan 2016 06:32:25 AM UTC, comment #1: 

It is the expected behaviour that `subsref` and `subsasgn` with operator syntax do not use overloaded methods.  Otherwise it would not be possible to access the object's internal data anymore.

So the plot.m method should be fixed and use something like this:

````
idx = struct ("type", "()", "subs", x)
plot (x, subsref (p, idx), varargin{:});

````

Oliver Heimlich <oheim>
Wed 13 Jan 2016 11:55:36 PM UTC, original submission:  

The failing code is taken from examples/code/@polynomial/plot.m.

The code is


function h = plot (p, varargin)
  n = 128;
  rmax = max (abs (roots (p.poly)));
  x = [0 : (n - 1)] / (n - 1) * 2.2 * rmax - 1.1 * rmax;
  if (nargout > 0)
    h = plot (x, p(x), varargin{:});
  else
    plot (x, p(x), varargin{:});
  endif
endfunction


The code makes use of overloading for the subsref function so that p(x) calculates the value of the polynomial at the points x.  Unfortunately, the overloaded subsref is not called and it is treated as normal indexing which then fails because some of the x values are not integers.


cd examples/code
../../run-octave -f --no-gui
p = polynomial ([1 0 1])
p = 1 + X ^ 2
plot (p)
error: p(-1.1): subscripts must be either integers 1 to (2^31)-1 or logicals
error: called from
    plot at line 10 column 5




Rik <rik5>
Group administrator

 

(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 oheim (Posted a comment)
  • -email is unavailable- added by rik5 (Submitted the item)
  •  

    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
    2016-01-14 rik5 StatusNone Fixed
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code