-
Notifications
You must be signed in to change notification settings - Fork 252
compiler: Check sympy_type returns a floating point type in the code printer
#2515
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -313,7 +313,7 @@ def test_cos_vs_cosf(): | |
|
|
||
| # Doesn't make much sense, but it's legal | ||
| c = dSymbol('c', dtype=np.int32) | ||
| assert ccode(cos(c)) == "cos(c)" | ||
| assert ccode(cos(c)) == "cosf(c)" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are correct, there is a bug here with your specific example. However, I think I introduced it in my last PR and it is specific to But, in this test, why should the resultant code be
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well |
||
|
|
||
|
|
||
| def test_intdiv(): | ||
|
|
||
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 don't think this is valid, this will return "is float" for integer and will break a lot of cases. This is probably only necessary for some limited cases like
cosbut not in generalThere 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 disagree a little bit here, the method is called
single_precnotis_float. If an expression only containing integers is passed, it is unclear that the result should return anything other than the default, as determined here byself.dtype.I could see an argument for following the sympy behaviour of returning
Noneif the precision cannot be determined, but this won't change much asbool(None) == bool(False) == False.In the bigger picture, there are a lot of issues coinciding here, it seems that
sympy_dtypeisn't quite fit for purpose and the printer is doing some rather rough type inference. Personally, I think home-grown type inference should be avoided here (at least for the purposes of this PR), but I am open to further suggestions.Uh oh!
There was an error while loading. Please reload this page.
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.
Well, sure, that's the name we used when we made it, but this is effectively an
is_float. This merely checks if it needs the float literal.self.dtype is only a last resort default for expression that cannot have a type determined, the type of the expression if determined is always the one that should be used irrespective of what that type is.