Skip to content

Array assignment with broadcasting is not working #1330

Closed
@antonwolfy

Description

@antonwolfy

The code below results in an exception, but is expected to work:

import numpy, dpctl, dpctl.tensor as dpt

x = numpy.ones((3, 1))
y = numpy.empty((2, 3, 4))

# works in numpy:
y[...] = x

a = dpt.ones((3, 1))
b = dpt.empty((2, 3, 4))

# dpctl raises the exception:
b[...] = a
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[5], line 1
----> 1 b[...] = a

File /localdisk/work/antonvol/code/dpctl/dpctl/tensor/_usmarray.pyx:1172, in dpctl.tensor._usmarray.usm_ndarray.__setitem__()
   1170     if Xv.size == 0:
   1171         return
-> 1172     _copy_from_usm_ndarray_to_usm_ndarray(Xv, rhs)
   1173 else:
   1174     if hasattr(rhs, "__sycl_usm_array_interface__"):

File /localdisk/work/antonvol/code/dpctl/dpctl/tensor/_copy_utils.py:283, in _copy_from_usm_ndarray_to_usm_ndarray(dst, src)
    281 if src.ndim < len(common_shape):
    282     new_src_strides = (0,) * (len(common_shape) - src.ndim) + src.strides
--> 283     src_same_shape = dpt.usm_ndarray(
    284         common_shape, dtype=src.dtype, buffer=src, strides=new_src_strides
    285     )
    286 else:
    287     src_same_shape = src

File /localdisk/work/antonvol/code/dpctl/dpctl/tensor/_usmarray.pyx:328, in dpctl.tensor._usmarray.usm_ndarray.__cinit__()
    326    (_offset + ary_max_displacement + 1) * itemsize > _buffer.nbytes):
    327     self._cleanup()
--> 328     raise ValueError(("buffer='{}' can not accomodate "
    329                       "the requested array.").format(buffer))
    330 is_fp64 = (typenum == UAR_DOUBLE or typenum == UAR_CDOUBLE)

ValueError: buffer='[[1.]
 [1.]
 [1.]]' can not accomodate the requested array.

Metadata

Metadata

Assignees

No one assigned

    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