-
Notifications
You must be signed in to change notification settings - Fork 294
Fix bool to int casting issue in Python
#1654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
| if F64Type.isinstance(left.type) and IntegerType.isinstance( | ||
| comparator.type): | ||
| left = arith.FPToSIOp(comparator.type, left).result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not following why the LHS, if it's a floating point value, is integer truncated here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is existing code from the isinstance(op, ast.Eq) below, which, in principle, should also be handled in the ast.NotEq case here.
I don't know the context of it so didn't change it or migrate it to cc.CastOp yet.
@khalatepradnya Do you know the intent of this float -> int conversion in equal check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope, sorry. Tagging @amccaskey for details.
I see that the comparator is of integer type and that the integer comparator is being used (arith.cmpi) on line#2740
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if this isn't a bug. Consider this python code
>>> a=1
>>> b=1.2
>>> c= b==a
>>> print(c)
False|
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
|
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
bool to int casting issue in Python
Description
When we need to check
if var == 1, wherevaris a bool type and 1 is an integer type, we need to do an unsigned extension of i1 since a signed extension of bool True will result in -1 rather than 1.Also, add the type casting logic to
NotEqas well since it should be equivalent toEq.Resolve: #1620