Skip to content

dpctl does not return a zero-length array when no reduction is going to be done #1456

Closed
@antonwolfy

Description

@antonwolfy

The below example behaves differently between dcptl and numpy:

import numpy, dpctl, dpctl.tensor as dpt

dpctl.__version__
# Out: '0.15.1dev0+63.g03fd73794'

a = numpy.ones((0, 2), dtype='f4')
numpy.min(a, axis=(1,))
# Out: array([], dtype=float32)

b = dpt.ones((0, 2), dtype='f4')
dpt.min(b, axis=(1,))
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[15], line 1
----> 1 dpt.min(b, axis=(1,))

File ~/miniconda3/envs/dpnp_dev/lib/python3.9/site-packages/dpctl/tensor/_reduction.py:499, in min(x, axis, keepdims)
    474 def min(x, axis=None, keepdims=False):
    475     """min(x, axis=None, dtype=None, keepdims=False)
    476
    477     Calculates the minimum value of the input array `x`.
   (...)
    497             array has the same data type as `x`.
    498     """
--> 499     return _comparison_over_axis(x, axis, keepdims, ti._min_over_axis)

File ~/miniconda3/envs/dpnp_dev/lib/python3.9/site-packages/dpctl/tensor/_reduction.py:421, in _comparison_over_axis(x, axis, keepdims, _reduction_fn)
    419 res_usm_type = x.usm_type
    420 if x.size == 0:
--> 421     raise ValueError("reduction does not support zero-size arrays")
    422 if red_nd == 0:
    423     return x

ValueError: reduction does not support zero-size arrays

As I can see python Array API notes the use case as implementation-defined. Should dpctl align the behavior with numpy here?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions