Skip to content
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

fix ldexp casting + unary ufunc dtypes #169

Merged
merged 5 commits into from
Aug 1, 2023
Merged

fix ldexp casting + unary ufunc dtypes #169

merged 5 commits into from
Aug 1, 2023

Conversation

ev-br
Copy link
Collaborator

@ev-br ev-br commented Aug 1, 2023

the second commit is just trivial MAINT while I'm looking at this file

@ev-br ev-br requested a review from lezcano August 1, 2023 12:04
@ev-br ev-br changed the title fix ldexp casting fix ldexp casting + unary ufunc dtypes Aug 1, 2023
Comment on lines 166 to 176
if dtype is not None:
if isinstance(x1, torch.Tensor):
x1 = _util.typecast_tensor(x1, dtype, casting)
else:
x1 = torch.as_tensor(x1, dtype=dtype)
else:
if not isinstance(x1, torch.Tensor):
x1 = torch.as_tensor(x1)
if _dtypes_impl._category(x1.dtype) < 2:
# cast integers to float64
x1 = x1.double()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we reuse the unary ufunc machinery for this one?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.double() is actually wrong because we allow for user control of the default dtypes, so it needs to be default_dtypes.float_dtype. Ditto for unary ufuncs, and I've extracted the relevant three-liner into _util in the updated PR. Does that count as a reuse in your books? :-).

Copy link
Collaborator

@lezcano lezcano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Factoring things out helps finding subtle bugs!

@ev-br ev-br merged commit f221f50 into main Aug 1, 2023
4 checks passed
@ev-br ev-br deleted the ldexp_casting branch August 1, 2023 16:15
@ev-br
Copy link
Collaborator Author

ev-br commented Aug 1, 2023

Merged, thanks for the review @lezcano !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants