pycuda icon indicating copy to clipboard operation
pycuda copied to clipboard

``GPUArray.zeros_like | ones_like`` failing for scalar inputs

Open mitkotak opened this issue 2 years ago • 0 comments

Here's the MWE

>>> import pycuda.autoinit
>>> import pycuda.gpuarray as gpuarray
>>> import numpy as np
>>> c = 42.0
>>> zero_array = np.zeros_like(c) # array(0.)
>>> zero_array_gpu = gpuarray.zeros_like(c) # Fails
>>> one_array = np.ones_like(c) # array(1.)
>>> one_array_gpu = gpuarray.ones_like(c) # Fails

Here's the error trace

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [15], in <cell line: 1>()
----> 1 gpuarray.zeros_like(c)

File ~/pycuda/pycuda/gpuarray.py:1422, in zeros_like(other_ary, dtype, order)
   1421 def zeros_like(other_ary, dtype=None, order="K"):
-> 1422     dtype, order, strides = _array_like_helper(other_ary, dtype, order)
   1423     result = GPUArray(
   1424         other_ary.shape, dtype, other_ary.allocator, order=order, strides=strides
   1425     )
   1426     zero = np.zeros((), result.dtype)

File ~/pycuda/pycuda/gpuarray.py:1394, in _array_like_helper(other_ary, dtype, order)
   1392         order = "C"
   1393 elif order == "K":
-> 1394     if other_ary.flags.c_contiguous or (other_ary.ndim <= 1):
   1395         order = "C"
   1396     elif other_ary.flags.f_contiguous:

AttributeError: 'float' object has no attribute 'flags'

mitkotak avatar Oct 27 '22 01:10 mitkotak