Skip to content

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

Description

@antonwolfy

The below example behaves differently between dcptl and numpy:

importnumpy, dpctl, dpctl.tensorasdptdpctl.__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,))
---------------------------------------------------------------------------ValueErrorTraceback (mostrecentcalllast)
CellIn[15], line1---->1dpt.min(b, axis=(1,))
File~/miniconda3/envs/dpnp_dev/lib/python3.9/site-packages/dpctl/tensor/_reduction.py:499, inmin(x, axis, keepdims)
474defmin(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 """-->499return_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)
419res_usm_type=x.usm_type420ifx.size==0:
-->421raiseValueError("reduction does not support zero-size arrays")
422ifred_nd==0:
423returnxValueError: reductiondoesnotsupportzero-sizearrays

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