bugGNU Octave - Bugs: bug #51252, incorrect type casting of colon...

 
 

bug #51252: incorrect type casting of colon operator ':'

Submitter:  Xiangmin Jiao <xmjiao>
Submitted:  Fri 16 Jun 2017 08:12:38 PM UTC
   
 
Category:  Interpreter Severity:  2 - Minor
Priority:  3 - Low Item Group:  Matlab Compatibility
Status:  Confirmed Assigned to:  None
Originator Name:  Xiangmin Jiao Open/Closed:  * Open
Release:  * 4.2.1 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 20 Jun 2017 03:45:32 PM UTC, comment #4: 

Interesting.  This will require a small project to implement correctly.  The Range object needs to be extended to do more input validation, and it needs a new private variable which records the output class.  Internally, everything can still be done with doubles but the output can be cast to the correct type whenever required.

For the time being, just casting the range to the desired type within a script file is the best solution.

Rik <rik5>
Group administrator
Tue 20 Jun 2017 11:13:23 AM UTC, comment #3: 

Output in Matlab R2016a:

>> x = int32 (1) : 0.25 : int32 (3)
Error using  :
Double operands interacting with int32 operands must have integer values.

>> class (uint8 (1) : 3)
ans =
uint8

>> class (1 : uint8 (3))
ans =
uint8

>> class (int32 (1) : uint8 (3))
Error using  :
Colon operands must be all the same type, or mixed with real scalar doubles.


Markus Mützel <mmuetzel>
Group administrator
Tue 20 Jun 2017 04:38:57 AM UTC, comment #2: 

What does Matlab return for


x = int32 (1) : 0.25 : int32 (3)


Also, what does this code return


class (uint8 (1) : 3)
class (1 : uint8 (3))
class (int32 (1) : uint8 (3))



Rik <rik5>
Group administrator
Mon 19 Jun 2017 07:12:52 PM UTC, comment #1: 

Yes, in Octave the colon expression returns a "range" object which is only implemented in terms of double values (or however the "colon" overload method of a user-defined class is defined).

If Matlab's colon expression preserves the standard type precedence of built in types, then some redesign work is needed in Octave to make this compatible.

OTOH it's very easy to write


int32 (1:10)


instead.

Mike Miller <mtmiller>
Group Member
Fri 16 Jun 2017 08:12:38 PM UTC, original submission:  

In Octave 3.8.1, 4.0.2 and 4.2.1, the ':' operator returns incorrect data types:
```
class( int32(1) : int32 (10))
```

It returns double. However, the expected answer is int32.

Similarly,
```
class( int32(1) : 10)
class( int32(1) : int32(1), int32(10))
class( single(1) : 10)
class( single(1) : single(1), single(10))
```

all return double, but the first two should return int32, and the last two should return single. I have observed this behavior in Ocatve 3.8.1, 4.0.2 and 4.2.1.

This is incompatible with MATLAB. It is also incompatible with the precedence of data types in Octave for other operators.  For example,
```
1 + int32(2)
```
returns an int32, so int32 takes precedence over double.

Therefore, it is clearly a bug.

Xiangmin Jiao <xmjiao>

 

(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 gyom
  • -email is unavailable- added by mmuetzel (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by xmjiao (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 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-11-21 gyom Carbon-Copy- Added gyom
    2019-02-26 mtmiller Carbon-CopyRemoved 80942 -
    2017-06-20 rik5 StatusNone Confirmed
    2017-06-19 mtmiller CategoryOctave Function Interpreter
        Severity3 - Normal 2 - Minor
        Priority5 - Normal 3 - Low
        Item GroupIncorrect Result Matlab Compatibility

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code