bugGNU Octave - Bugs: bug #53007, logical scalar values are...

 
 

bug #53007: logical scalar values are transformed to doubles upon indexing

Submitter:  Rik <rik5>
Submitted:  Mon 29 Jan 2018 10:30:51 PM UTC
   
 
Category:  GUI 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
   

Jump to the original submission

Fri 02 Feb 2018 04:08:27 PM UTC, comment #8: 

Interesting.  Well, Octave is no worse, just different, from Matlab in that it allows the conversion to occur.

That wraps up this report.  Marking as fixed and closing report.

Rik <rik5>
Group administrator
Fri 02 Feb 2018 06:16:58 AM UTC, comment #7: 

@Rik

In MATLAB R2017a:


>> x = false;
>> x(1) = 2i;
Complex values cannot be converted to logicals.


In fact this applies in general:


>> logical(2i)
Error using logical
Complex values cannot be converted to logicals.


Amro <amro_octave>
Tue 30 Jan 2018 09:05:01 PM UTC, comment #6: 

Patch works for me.

@Michael: Could you run one more test with Matlab?


x = false
x(1) = 2i
class (x)



Rik <rik5>
Group administrator
Tue 30 Jan 2018 07:19:40 PM UTC, comment #5: 

I pushed the following changeset:

http://hg.savannah.gnu.org/hgweb/octave/rev/6daa29105d21

It seems to fix the problem for me.

John W. Eaton <jwe>
Group administrator
Tue 30 Jan 2018 12:22:11 AM UTC, comment #4: 

Re-titling report.  This is actually an issue with how the interpreter handles indexing of a logical scalar.

Rik <rik5>
Group administrator
Mon 29 Jan 2018 11:50:30 PM UTC, comment #3: 

Rik: comment 2:

                                               < M A T L A B (R) >
                                      Copyright 1984-2017 The MathWorks, Inc.
                                       R2017b (9.3.0.713579) 64-bit (glnxa64)
                                                 September 14, 2017

 
To get started, type one of these: helpwin, helpdesk, or demo.
For product information, visit www.mathworks.com.
 

>> y = true


y =

  logical

   1

>> y(1) = 0


y =

  logical

   0

>> class (y)


ans =

    'logical'

>>


Michael Godfrey <godfrey>
Group Member
Mon 29 Jan 2018 10:51:57 PM UTC, comment #2: 

Hah, you're right.  I think this is a failing back in the interpreter.  Sample code:


>> x = uint8 (4)
x = 4
>> x(1) = 1000
x = 255
>> class (x)
ans = uint8
>> y = true
y = 1
>> y(1) = 0
y = 0
>> class (y)
ans = double


For someone who has acess to Matlab, try


y = true
y(1) = 0
class (y)


Is the final reported class "double" or "logical"?


Rik <rik5>
Group administrator
Mon 29 Jan 2018 10:43:59 PM UTC, comment #1: 

Oh.  I think this only happens with scalar logical values.

The variable editor is just evaluating an expression like


x(1,1) = new_value;


in the interpreter.  For arrays, the type remains the same, even for logicals.  But I do see the warning


warning: value not equal to 1 or 0 converted to logical 1


But for scalars, even the expression


x(1,1) = 1


will change a scalar logical value to double.

I suppose you are right that applying the class constructor to the RHS should fix this problem.  And also avoid the warning in the matrix case.

However, for numeric types, I'm not sure that we want to force the type to remain the same.  What does Matlab do (for logical, and numeric types, scalar and array)?  (Not that I will agree with it, but it might avoid future bug reports from surprised Matlab users).

John W. Eaton <jwe>
Group administrator
Mon 29 Jan 2018 10:30:51 PM UTC, original submission:  

Steps to Reproduce:


x = true;
openvar x
class (x)
ans = logical
# Note: class of object displayed is 1x1 logical
# Edit x and change the value to 0
class (x)
ans = double


Note that this doesn't happen for other class types such as single, uint8, etc.  Presumably, there is somewhere in the code that the input "val" is evaluated and it should be wrapped by the class of the object.


final_val = feval (class_type, val);



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

Digest:
   bug dependencies.

 

Carbon-Copy List
  • -email is unavailable- added by amro_octave (Posted a comment)
  • -email is unavailable- added by godfrey (Posted a comment)
  • -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.

     

    Follow 9 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-01-11 siko1056 Dependencies- bugs #55445 is dependent
    2018-02-02 rik5 StatusIn Progress Fixed
        Open/ClosedOpen Closed
    2018-01-30 rik5 StatusReady For Test In Progress
    2018-01-30 jwe CategoryInterpreter GUI
        StatusConfirmed Ready For Test
    2018-01-30 rik5 CategoryGUI Interpreter
    2018-01-30 rik5 StatusNone Confirmed
        SummaryVariable editor: logical values are transformed to doubles upon editing logical scalar values are transformed to doubles upon indexing

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code