inducer / inducer/pycuda

can't create GPUArray with shape stored as an ndarray

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

Description

Passing a shape stored in an ndarray to the GPUArray constructor raises an exception because of ndarray broadcasting:

```
In [1]: import numpy, pycuda.autoinit, pycuda.gpuarray

In [2]: pycuda.gpuarray.empty(np.array([1,2]), np.float32)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
in ()
----> 1 pycuda.gpuarray.empty(np.array([1,2]), np.float32)

/home/lev/Work/miniconda/envs/DEFAULT/lib/python2.7/site-packages/pycuda-2015.1.3-py2.7-linux-x86_64.egg/pycuda/gpuarray.pyc in __init__(self, shape, dtype, allocator, base, gpudata, strides, order)
182 elif order == "C":
183 strides = _c_contiguous_strides(
--> 184 dtype.itemsize, shape)
185 else:
186 raise ValueError("invalid order: %s" % order)

/home/lev/Work/miniconda/envs/DEFAULT/lib/python2.7/site-packages/pycuda-2015.1.3-py2.7-linux-x86_64.egg/pycuda/compyte/array.pyc in c_contiguous_strides(itemsize, shape)
37
38 def c_contiguous_strides(itemsize, shape):
---> 39 if shape:
40 strides = [itemsize]
41 for s in shape[:0:-1]:

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
```

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.