Disable implicit casting by default and implement intrinsic functions for casting - #1271
Conversation
|
|
||
| for i in range(dim1d): | ||
| assert abs(g[i] - 2*(i + 1)) <= eps | ||
| assert f64(abs(g[i] - f64(2*(i + 1)))) <= eps |
There was a problem hiding this comment.
I think the outer f64 is not necessary? I think abs of f64 should return an f64.
| # for l in range(256): | ||
| # i = i32(l/16) | ||
| # j = (l - i*16) | ||
| # assert abs(observed[l]**f32(2.0) - f32(i + j)) <= eps |
There was a problem hiding this comment.
Why are these commented out?
There was a problem hiding this comment.
I forgot to uncomment them after debugging.
| "stderr_hash": "28509dd59a386eebd632340a550d14299cd2a921ef6dc3ac7dbe7fe9", | ||
| "returncode": 0 | ||
| "stderr_hash": "d862bc9fbb666cb9925f68e2e3494851ee5d21f55e629078df671b83", | ||
| "returncode": 2 |
| @vectorize | ||
| def radians(x: f32) -> f32: | ||
| return x*pi_32/180 | ||
| return x*f32(pi_32/f32(180.0)) |
There was a problem hiding this comment.
Can this be written just as:
x*pi_32/f32(180)
? Or will that not work.
There was a problem hiding this comment.
Actually / operator always returns f64 type. This is because I think CPython always returns float with / operator. float is equivalent to f64 so we need to manually cast it to f32.
There was a problem hiding this comment.
This was happening implicitly but now got visibility when implicit casting is turned off.
There was a problem hiding this comment.
I see. Yes, Python returns float for /.
But we currently do f32 * f32 -> f32, that is, multiplication keeps the kind of the floating point. So why not also do f32 / f32 -> f32 and make the division keep the kind?
In Python it is simply float * float -> float and float / float -> float.
There was a problem hiding this comment.
Makes sense. I am +1 on this.
| --> tests/errors/kwargs_02_error.py:9:5 | ||
| | | ||
| 9 | arg3 = 3.0 | ||
| | ^^^^ ^^^ type mismatch ('f32' and 'f64') |
There was a problem hiding this comment.
This error message has changed.
| 4 | c.real = 5.0 | ||
| | ^^^^^^^^^^^^ | ||
| 3 | c = complex(3, 4) | ||
| | ^ ^^^^^^^^^^^^^ type mismatch ('c32' and 'c64') |
There was a problem hiding this comment.
This seems like a different error? I think you need to cast it first, so that you get to the actual error that we want to test.
| 8 | print(c1 | c2) | ||
| | ^^^^^^^ | ||
| 5 | c1 = 4+5j | ||
| | ^ ^^ type mismatch (i32 and c64) |
certik
left a comment
There was a problem hiding this comment.
I think this is good enough. The rest we can fix later as we discover issues.
Thanks @czgdp1807 for this monumental work. Very helpful! This provides us with a solid base. We can always implement inference or implicit rules later without breaking backwards compatibility.
Overrides #1194