Skip to content

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

Closed

Description

@antonwolfy

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.

Activity

  1. 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[/+] on Mar 26, 2025
  2. ndgrigorian commented on Mar 27, 2025

    @ndgrigorian
    Collaborator

    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.

  3. self-assigned this
    on Mar 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions