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

           x = n / self
        """

        if isinstance(other, GPUArray):
            if not self.flags.forc or not other.flags.forc:
                raise RuntimeError("only contiguous arrays may "
                                   "be used as arguments to this operation")

            result = self._new_like_me(_get_common_dtype(self, other))

            func = elementwise.get_divide_kernel()
            func.prepared_async_call(self._grid, self._block, None,
                                     other.gpudata, self.gpudata,
                                     result.gpudata, self.mem_size)

            return result
        else:
            if other == 1:
                return self
            else:
                # create a new array for the result
                result = self._new_like_me()
                return self._rdiv_scalar(other, result)
Exemplo n.º 2
0
    def __rdiv__(self,other):
        """Divides an array by a scalar or an array::

           x = n / self
        """

        if isinstance(other, GPUArray):
            if not self.flags.forc or not other.flags.forc:
                raise RuntimeError("only contiguous arrays may "
                        "be used as arguments to this operation")

            result = self._new_like_me(_get_common_dtype(self, other))

            func = elementwise.get_divide_kernel()
            func.prepared_async_call(self._grid, self._block, None,
                    other.gpudata, self.gpudata, result.gpudata,
                    self.mem_size)

            return result
        else:
            if other == 1:
                return self
            else:
                # create a new array for the result
                result = self._new_like_me()
                return self._rdiv_scalar(other, result)
Exemplo n.º 3
0
 def __mul__(self, other):
     if isinstance(other, GPUArray):
         result = self._new_like_me(_get_common_dtype(self, other))
         return self._elwise_multiply(other, result)
     else:
         result = self._new_like_me()
         return self._axpbz(other, 0, result)
Exemplo n.º 4
0
 def __mul__(self, other):
     if isinstance(other, GPUArray):
         result = self._new_like_me(_get_common_dtype(self, other))
         return self._elwise_multiply(other, result)
     else:
         result = self._new_like_me()
         return self._axpbz(other, 0, result)
Exemplo n.º 5
0
    def __sub__(self, other):
        """Substract an array from an array or a scalar from an array."""

        if isinstance(other, GPUArray):
            result = self._new_like_me(_get_common_dtype(self, other))
            return self._axpbyz(1, other, -1, result)
        else:
            if other == 0:
                return self
            else:
                # create a new array for the result
                result = self._new_like_me()
                return self._axpbz(1, -other, result)
Exemplo n.º 6
0
    def __sub__(self, other):
        """Substract an array from an array or a scalar from an array."""

        if isinstance(other, GPUArray):
            result = self._new_like_me(_get_common_dtype(self, other))
            return self._axpbyz(1, other, -1, result)
        else:
            if other == 0:
                return self
            else:
                # create a new array for the result
                result = self._new_like_me()
                return self._axpbz(1, -other, result)
Exemplo n.º 7
0
    def __add__(self, other):
        """Add an array with an array or an array with a scalar."""

        if isinstance(other, GPUArray):
            # add another vector
            result = self._new_like_me(_get_common_dtype(self, other))
            return self._axpbyz(1, other, 1, result)
        else:
            # add a scalar
            if other == 0:
                return self
            else:
                result = self._new_like_me()
                return self._axpbz(1, other, result)
Exemplo n.º 8
0
    def __add__(self, other):
        """Add an array with an array or an array with a scalar."""

        if isinstance(other, GPUArray):
            # add another vector
            result = self._new_like_me(_get_common_dtype(self, other))
            return self._axpbyz(1, other, 1, result)
        else:
            # add a scalar
            if other == 0:
                return self
            else:
                result = self._new_like_me()
                return self._axpbz(1, other, result)
Exemplo n.º 9
0
    def __div__(self, other):
        """Divides an array by an array or a scalar::

           x = self / n
        """
        if isinstance(other, GPUArray):
            result = self._new_like_me(_get_common_dtype(self, other))
            return self._div(other, result)
        else:
            if other == 1:
                return self
            else:
                # create a new array for the result
                result = self._new_like_me()
                return self._axpbz(1/other, 0, result)
Exemplo n.º 10
0
    def __div__(self, other):
        """Divides an array by an array or a scalar::

           x = self / n
        """
        if isinstance(other, GPUArray):
            result = self._new_like_me(_get_common_dtype(self, other))
            return self._div(other, result)
        else:
            if other == 1:
                return self
            else:
                # create a new array for the result
                result = self._new_like_me()
                return self._axpbz(1 / other, 0, result)
Exemplo n.º 11
0
    def __pow__(self, other):
        """pow function::

           example:
                   array = pow(array)
                   array = pow(array,4)
                   array = pow(array,array)

        """

        if isinstance(other, GPUArray):
            if not self.flags.forc or not other.flags.forc:
                raise RuntimeError("only contiguous arrays may "
                        "be used as arguments to this operation")

            assert self.shape == other.shape

            result = self._new_like_me(_get_common_dtype(self, other))

            func = elementwise.get_pow_array_kernel(
                    self.dtype, other.dtype, result.dtype)

            func.prepared_async_call(self._grid, self._block, None,
                    self.gpudata, other.gpudata, result.gpudata,
                    self.mem_size)

            return result
        else:
            if not self.flags.forc:
                raise RuntimeError("only contiguous arrays may "
                        "be used as arguments to this operation")

            result = self._new_like_me()
            func = elementwise.get_pow_kernel(self.dtype)
            func.prepared_async_call(self._grid, self._block, None,
                    other, self.gpudata, result.gpudata,
                    self.mem_size)

            return result
Exemplo n.º 12
0
    def __pow__(self, other):
        """pow function::

           example:
                   array = pow(array)
                   array = pow(array,4)
                   array = pow(array,array)

        """

        if isinstance(other, GPUArray):
            if not self.flags.forc or not other.flags.forc:
                raise RuntimeError("only contiguous arrays may "
                                   "be used as arguments to this operation")

            assert self.shape == other.shape

            result = self._new_like_me(_get_common_dtype(self, other))

            func = elementwise.get_pow_array_kernel(self.dtype, other.dtype,
                                                    result.dtype)

            func.prepared_async_call(self._grid, self._block, None,
                                     self.gpudata, other.gpudata,
                                     result.gpudata, self.mem_size)

            return result
        else:
            if not self.flags.forc:
                raise RuntimeError("only contiguous arrays may "
                                   "be used as arguments to this operation")

            result = self._new_like_me()
            func = elementwise.get_pow_kernel(self.dtype)
            func.prepared_async_call(self._grid, self._block, None, other,
                                     self.gpudata, result.gpudata,
                                     self.mem_size)

            return result
Exemplo n.º 13
0
 def mul_add(self, selffac, other, otherfac, add_timer=None, stream=None):
     """Return `selffac * self + otherfac*other`.
     """
     result = self._new_like_me(_get_common_dtype(self, other))
     return self._axpbyz(selffac, other, otherfac, result, add_timer)
Exemplo n.º 14
0
 def mul_add(self, selffac, other, otherfac, add_timer=None, stream=None):
     """Return `selffac * self + otherfac*other`.
     """
     result = self._new_like_me(_get_common_dtype(self, other))
     return self._axpbyz(selffac, other, otherfac, result, add_timer)