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

dpctl.tensor returns int8 arrays from ceil, trunc and floor function for bool input array #2030

Closed
antonwolfy opened this issue Mar 26, 2025 · 1 comment · Fixed by #2033
Closed
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@antonwolfy
Copy link
Collaborator

antonwolfy commented Mar 26, 2025

The example below works differently with numpy:

import numpy as np, dpctl, dpctl.tensor as dpt

np.__version__
# Out: '2.2.4'

dpctl.__version__
# Out: '0.20.0dev0+71.gc5d18f4b6f'

a = np.ones(5, dtype='?')
ia = dpt.ones(5, dtype='?')

np.ceil(a).dtype
# Out: dtype('bool')

np.trunc(a).dtype
# Out: dtype('bool')

np.floor(a).dtype
# Out: dtype('bool')

dpt.ceil(ia).dtype
# Out: dtype('int8')

dpt.trunc(ia).dtype
# Out: dtype('int8')

dpt.floor(ia).dtype
# Out: dtype('int8')

In overall, it seems Python array API standard requires dtype of output array to be matched with dtype of input array:

out (array) – an array containing the rounded result for each element in x. The returned array must have the same data type as x.

Although the support of bool dtypes is not mandated:

x (array) – input array. Should have a real-valued data type.

It sounds like if dpctl provides the support of bool dtype, it has to return out array of bool dtype also.

@antonwolfy antonwolfy changed the title dpt.tensor returns int8 arrays from ceil, trunc and floor function for bool input array dpctl.tensor returns int8 arrays from ceil, trunc and floor function for bool input array Mar 26, 2025
@ndgrigorian
Copy link
Collaborator

ndgrigorian commented Mar 27, 2025

Although the support of bool dtypes is not mandated:

x (array) – input array. Should have a real-valued data type.

This is the most important point, everything outside of real-valued is undefined behavior, so the current behavior doesn't disobey the spec.

We don't return a bool array because we chose not to implement a loop for bool in these cases, but supporting the bool->bool loop would be fine, in my opinion.

@ndgrigorian ndgrigorian added enhancement New feature or request good first issue Good for newcomers labels Mar 27, 2025
@vtavana vtavana self-assigned this Mar 27, 2025
vtavana added a commit to IntelPython/dpnp that referenced this issue Apr 9, 2025
Removes w/a related to IntelPython/dpctl#2030.

---------

Co-authored-by: Anton <[email protected]>
github-actions bot added a commit to IntelPython/dpnp that referenced this issue Apr 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
3 participants