inducer / inducer/pycuda

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

Open
#389 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
2.1k
Forks
298
Avg merge
4m
Merged PRs (30d)
1

Description

Here's the MWE

```python
>>> 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

```console
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Input In [15], in ()
----> 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'
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.