Skip to content

Fix out of bounds integer behavior in dpctl.tensor.full #1266

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

Merged
merged 1 commit into from
Jun 28, 2023

Conversation

ndgrigorian
Copy link
Collaborator

Resolves #1230

This PR adjusts how integer overflow and underflow is handled by dpctl.tensor.full.

Previously, when an integer that would overflow the type of array in the result of full was passed in as fill_value, an exception would be thrown by pybind11.

Now, _to_scalar is used to get fill value back after it has been converted to a Numpy scalar, which brings the value into the range of the type and allows pybind11 to unpack the scalar.

  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to an issue with a reproducer?
  • Have you tested your changes locally for CPU and GPU devices?
  • Have you made sure that new changes do not introduce compiler warnings?
  • Have you checked performance impact of proposed changes?
  • If this PR is a work in progress, are you opening the PR as a draft?

@ndgrigorian ndgrigorian requested a review from npolina4 June 28, 2023 00:37
@github-actions
Copy link

@coveralls
Copy link
Collaborator

Coverage Status

coverage: 83.261% (+0.005%) from 83.256% when pulling 3a814f6 on full-large-integer-fix into cc02941 on master.

@ndgrigorian ndgrigorian requested a review from antonwolfy June 28, 2023 01:22
@github-actions
Copy link

Array API standard conformance tests for dpctl=0.14.5dev0=py310h7bf5fec_3 ran successfully.
Passed: 388
Failed: 612
Skipped: 119

@antonwolfy
Copy link
Collaborator

antonwolfy commented Jun 28, 2023

I've tried to test the built Win package and the behavior is still different and looks incorrect:

numpy.full(3, 4294967295)
Out: array([4294967295, 4294967295, 4294967295], dtype=int64)

dpt.full(3, 4294967295)
Out: usm_ndarray([-1, -1, -1], dtype=int32)

looks fill_value was just silently casted to int32, but expected int64.

@ndgrigorian
Copy link
Collaborator Author

I've tried to test the built Win package and the behavior is still different and looks incorrect:

numpy.full(3, 4294967295)
Out: array([4294967295, 4294967295, 4294967295], dtype=int64)

dpt.full(3, 4294967295)
Out: usm_ndarray([-1, -1, -1], dtype=int32)

looks fill_value was just silently casted to int32, but expected int64.

Yes, this is to keep our conformity to the array API spec, which requires the output type be the default integer type.

Any possible changes to the default integer type on Windows will be made in a separate PR.

@antonwolfy
Copy link
Collaborator

I've tried to test the built Win package and the behavior is still different and looks incorrect:

numpy.full(3, 4294967295)
Out: array([4294967295, 4294967295, 4294967295], dtype=int64)

dpt.full(3, 4294967295)
Out: usm_ndarray([-1, -1, -1], dtype=int32)

looks fill_value was just silently casted to int32, but expected int64.

Yes, this is to keep our conformity to the array API spec, which requires the output type be the default integer type.

Any possible changes to the default integer type on Windows will be made in a separate PR.

Ok, I see. Thank you @ndgrigorian! I have no more comments. LGTM!

@ndgrigorian ndgrigorian merged commit 0506a49 into master Jun 28, 2023
@github-actions
Copy link

Deleted rendered PR docs from intelpython.github.com/dpctl, latest should be updated shortly. 🤞

@github-actions
Copy link

Array API standard conformance tests for dpctl=0.14.5dev0=py310h7bf5fec_3 ran successfully.
Passed: 388
Failed: 612
Skipped: 119

@antonwolfy antonwolfy deleted the full-large-integer-fix branch June 29, 2023 10:04
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.

dpctl.tensot.full() RuntimeError: Unable to cast Python instance to C++ type
3 participants