bugGNU Octave - Bugs: bug #53231, Range type should implement...

 
 

bug #53231: Range type should implement division operator for scalars

Submitter:  Rik <rik5>
Submitted:  Tue 27 Feb 2018 01:43:27 AM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Feature Request
Status:  Confirmed Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 27 Feb 2018 07:34:29 PM UTC, comment #3: 

As an additional data point, see bug #53199 where the extra accuracy of a Range, versus a Matrix, data type was crucial to resolving the bug.

Rik <rik5>
Group administrator
Tue 27 Feb 2018 04:01:53 AM UTC, comment #2: 

See also bug #50924.  Some care needs to be used when implementing these operators.  Otherwise, if accuracy and/or compatibility is important, we should probably limit the range type to be used in only a few cases (for loop ranges, for example), same as Matlab.

John W. Eaton <jwe>
Group administrator
Tue 27 Feb 2018 02:00:18 AM UTC, comment #1: 

To be clear, only a range divided by a scalar needs to be implemented, and not the reverse.  In other words, this function


  friend OCTAVE_API Range operator / (const Range& r, double x);



Rik <rik5>
Group administrator
Tue 27 Feb 2018 01:43:27 AM UTC, original submission:  

While fixing a bug in hist.m I accidentally discovered that division by a scalar is not implement for Range values.

For example:


octave:2> x = 1:10
x =

    1    2    3    4    5    6    7    8    9   10

octave:3> typeinfo (x)
ans = range
octave:4> y = 3 * x
y =

    3    6    9   12   15   18   21   24   27   30

octave:5> typeinfo (y)
ans = range
octave:6> z = x / 1
z =

    1    2    3    4    5    6    7    8    9   10

octave:7> typeinfo (z)
ans = matrix


This is rather surprising and likely to trip up users.

I was able to work around the limitation by using multiplication, but the code looks awkward.


new_range = old_range * (1/scalar)


The issue is confirmed by looking at liboctave/array/Range.h where the list of operators implemented does not include division.


  friend OCTAVE_API Range operator - (const Range& r);
  friend OCTAVE_API Range operator + (double x, const Range& r);
  friend OCTAVE_API Range operator + (const Range& r, double x);
  friend OCTAVE_API Range operator - (double x, const Range& r);
  friend OCTAVE_API Range operator - (const Range& r, double x);
  friend OCTAVE_API Range operator * (double x, const Range& r);
  friend OCTAVE_API Range operator * (const Range& r, double x);


This seems like a simple enough fix to introduce function prototypes for division by a scalar in Range.h and copy/modify the existing multiplication code in Range.cc to work for division.

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 jwe (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.

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-02-27 rik5 StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-3230.
    Corresponding source code