Skip to content

__add__ fails for empty array inputs #391

Description

@mitkotak

Here's the MWE

>>> import pycuda.autoinit
>>> import pycuda.gpuarray as gpuarray
>>> import numpy as np
>>> empty_array = np.array([])
>>> empty_array_gpu = gpuarray.to_gpu(empty_array)
>>> result_array = empty_array + 0 # array([], dtype=float64)
>>> result_array_gpu = -empty_array_gpu + 0 # Fails

Here's the error trace

---------------------------------------------------------------------------
ArgumentError                             Traceback (most recent call last)
Input In [29], in <cell line: 1>()
----> 1 empty_array_gpu + 0

File ~/pycuda/pycuda/gpuarray.py:593, in GPUArray.__add__(self, other)
    590 elif np.isscalar(other):
    591     # add a scalar
    592     if other == 0:
--> 593         return self.copy()
    594     else:
    595         result = self._new_like_me(_get_common_dtype(self, other))

File ~/pycuda/pycuda/gpuarray.py:393, in GPUArray.copy(self)
    391 def copy(self):
    392     new = GPUArray(self.shape, self.dtype, self.allocator)
--> 393     _memcpy_discontig(new, self)
    394     return new

File ~/pycuda/pycuda/gpuarray.py:1570, in _memcpy_discontig(dst, src, async_, stream)
   1566         drv.memcpy_dtod_async(
   1567             dst.gpudata, src.gpudata, src.nbytes, stream=stream
   1568         )
   1569     else:
-> 1570         drv.memcpy_dtod(dst.gpudata, src.gpudata, src.nbytes)
   1571 else:
   1572     # The arrays might be contiguous in the sense of
   1573     # having no gaps, but the axes could be transposed
   1574     # so that the order is neither Fortran or C.
   1575     # So, we attempt to get a contiguous view of dst.
   1576     dst = _as_strided(dst, shape=(dst.size,), strides=(dst.dtype.itemsize,))

ArgumentError: Python argument types in
    pycuda._driver.memcpy_dtod(NoneType, NoneType, int)
did not match C++ signature:
    memcpy_dtod(unsigned long long dest, unsigned long long src, unsigned long size)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions