Exemplo n.º 1
0
def _copy(self, self_ref, other_ref):
    if (len(other_ref) <= len(self_ref)):
        from pycuda.elementwise import get_copy_kernel
        func = get_copy_kernel(self.dtype, other_ref.dtype)
        func.prepared_async_call(self_ref._grid, self_ref._block, None,
                                 self_ref.gpudata, other_ref.gpudata,
                                 self_ref.mem_size)
    else:
        raise RuntimeError("The arrays must the same length")
Exemplo n.º 2
0
def _copy(self, self_ref, other_ref):
    if (len(other_ref) <= len(self_ref)) :
        from pycuda.elementwise import get_copy_kernel
        func = get_copy_kernel(self.dtype, other_ref.dtype)
        func.prepared_async_call(self_ref._grid, self_ref._block, None,
                self_ref.gpudata, other_ref.gpudata,
                self_ref.mem_size)
    else:
        raise RuntimeError("The arrays must the same length")
Exemplo n.º 3
0
    def astype(self, dtype, stream=None):
        if dtype == self.dtype:
            return self

        result = self._new_like_me(dtype=dtype)

        func = elementwise.get_copy_kernel(dtype, self.dtype)
        func.set_block_shape(*self._block)
        func.prepared_async_call(self._grid, stream, result.gpudata,
                                 self.gpudata, self.mem_size)

        return result
Exemplo n.º 4
0
    def astype(self, dtype, stream=None):
        if dtype == self.dtype:
            return self

        result = self._new_like_me(dtype=dtype)

        func = elementwise.get_copy_kernel(dtype, self.dtype)
        func.set_block_shape(*self._block)
        func.prepared_async_call(self._grid, stream,
                result.gpudata, self.gpudata,
                self.mem_size)

        return result
Exemplo n.º 5
0
    def astype(self, dtype, stream=None):
        if not self.flags.forc:
            raise RuntimeError("only contiguous arrays may " "be used as arguments to this operation")

        if dtype == self.dtype:
            return self

        result = self._new_like_me(dtype=dtype)

        func = elementwise.get_copy_kernel(dtype, self.dtype)
        func.prepared_async_call(self._grid, self._block, stream, result.gpudata, self.gpudata, self.mem_size)

        return result
Exemplo n.º 6
0
    def astype(self, dtype, stream=None):
        if not self.flags.forc:
            raise RuntimeError("only contiguous arrays may "
                               "be used as arguments to this operation")

        if dtype == self.dtype:
            return self

        result = self._new_like_me(dtype=dtype)

        func = elementwise.get_copy_kernel(dtype, self.dtype)
        func.prepared_async_call(self._grid, self._block, stream,
                                 result.gpudata, self.gpudata, self.mem_size)

        return result
Exemplo n.º 7
0
    def __setitem__(self, index, other):
        if isinstance(other, Array):

            if self.kind is 'real' and other.kind is 'complex':
                raise ValueError('Cannot set real value with complex')

            if isinstance(index, slice):
                self_ref = self._data[index]
                other_ref = other._data
            else:
                self_ref = self._data[index:index + 1]
                other_ref = other._data

            if type(self._data) is _numpy.ndarray:
                self_ref[:] = other_ref[:]

            elif _pycbc.HAVE_CUDA and type(self._data) is _cudaarray.GPUArray:
                if (len(other_ref) <= len(self_ref)):
                    from pycuda.elementwise import get_copy_kernel
                    func = get_copy_kernel(self.dtype, other.dtype)
                    func.prepared_async_call(self_ref._grid, self_ref._block,
                                             None, self_ref.gpudata,
                                             other_ref.gpudata,
                                             self_ref.mem_size)
                else:
                    raise RuntimeError("The arrays must the same length")

            elif _pycbc.HAVE_OPENCL and type(self._data) is _openclarray.Array:
                raise NotImplementedError

        elif type(other) in _ALLOWED_SCALARS:
            if isinstance(index, slice):
                self[index].fill(other)
            else:
                self[index:index + 1].fill(other)

        else:
            raise TypeError('Can only copy data from another Array')