Ejemplo n.º 1
0
    def __rdiv__(self,other):
        """Divides an array by a scalar or an array::

           x = n / self
        """

        if isinstance(other, (int, float, complex)):
            # if array - 0 than just return the array since its the same anyway
            if other == 0:
                return self
            else:
                # create a new array for the result
                result = GPUArray(self.shape, self.dtype)
                return self._rdiv_scalar(other, result)
        else:
            result = GPUArray(self.shape, self.dtype)

            assert self.dtype == numpy.float32
            assert self.shape == other.shape
            assert self.dtype == other.dtype

            kernel._get_divide_kernel()(other.gpudata, self.gpudata,
                    out.gpudata, numpy.int32(self.size),
                    **self._kernel_kwargs)

            return result
Ejemplo n.º 2
0
    def _div(self, other, out):
        """Divides an array by another array."""

        assert self.dtype == numpy.float32
        assert self.shape == other.shape
        assert self.dtype == other.dtype

        block_count, threads_per_block, elems_per_block = splay(self.size, WARP_SIZE, 128, 80)

        kernel._get_divide_kernel()(self.gpudata, other.gpudata,
                out.gpudata, numpy.int32(self.size),
                **self._kernel_kwargs)

        return out