modularml / mojo

The Mojo Programming Language
https://docs.modular.com/mojo/manual/
Other
23.31k stars 2.59k forks source link

[BUG] Return values are correct, but REPL reports incorrect #3480

Open DWSimmons opened 2 months ago

DWSimmons commented 2 months ago

Bug description

Reported boolean values of REPL do not match reported values of print output

Steps to reproduce

1) magic init project --mojoproject 2) cd project 3) magic s 4) magic run mojo

The following code compares values and returns the correct string bool but the REPL reports the value as incorrect.

  1> alias Vec4 = SIMD[DType.int32, 4] 
  2. var a = Vec4(1,1,0,0) 
  3. var b = Vec4(0,0,0,0) 
  4. print(a > b) 
  5. cmp = a > b 
  6. print(cmp) 
  7.  
[True, True, False, False]
[True, True, False, False]
(SIMD[int32, 4]) a = {
  (si32) [0] = 1
  (si32) [1] = 1
  (si32) [2] = 0
  (si32) [3] = 0
}
(SIMD[int32, 4]) b = {
  (si32) [0] = 0
  (si32) [1] = 0
  (si32) [2] = 0
  (si32) [3] = 0
}
(SIMD[bool, 4]) cmp = {
  (i1) [0] = True
  (i1) [1] = False
  (i1) [2] = True
  (i1) [3] = True
}

cmp[0] is True # good, 1 > 0 cmp[1] is False # no good 1 is still greater than 0 cmp[2] and cmp[3] is True # no good, both incorrect as 0 is not greather than 0.


I tried a different approach as I was curious if the type assignment made a difference for cmp and I got different results...

1> alias Vec4 = SIMD[DType.int32, 4] 
  2. var a = Vec4(1,1,0,0) 
  3. var b = Vec4(0,0,0,0) 
  4. var cmp : SIMD[DType.bool, 4] 
  5. cmp = a > b 
  6. print(a > b) 
  7. print(cmp) 
  8.  
[True, True, False, False]
[True, True, False, False]
(SIMD[int32, 4]) a = {
  (si32) [0] = 1
  (si32) [1] = 1
  (si32) [2] = 0
  (si32) [3] = 0
}
(SIMD[int32, 4]) b = {
  (si32) [0] = 0
  (si32) [1] = 0
  (si32) [2] = 0
  (si32) [3] = 0
}
(SIMD[bool, 4]) cmp = {
  (i1) [0] = True
  (i1) [1] = True
  (i1) [2] = True
  (i1) [3] = True

While printed output is correct, REPL variable assignment is not All True should be True, True, False, False.

System information

- What OS did you do install Mojo on ?
Ubuntu 22.04.0
- Provide version information for Mojo by pasting the output of `mojo -v`
(one) darin@home:/media/darin/M2/magic/one$ magic run mojo --version
mojo 24.5.0 (e8aacb95)
magic 0.2.3
soraros commented 2 months ago

Duplicate of #3379.

DWSimmons commented 2 months ago

Agreed duplicate.