示例#1
0
文件: parray.py 项目: bionet/vtem
 def rsub(self, other):
     """
     substract other by self
     inplace if possible
     """
     if isinstance(other, PitchArray):
         if self.shape != other.shape:
             raise ValueError("array dimension misaligned")
         dtype = _get_common_dtype(self, other)
         if self.dtype == dtype:
             result = self
         else:
             result = self._new_like_me(dtype = dtype)
             
         if self.size:
             if self.M == 1:
                 func = pu.get_subarray_function(other.dtype, self.dtype, result.dtype, pitch = False)
                 func.prepared_call(self._grid, self._block, result.gpudata, other.gpudata, self.gpudata, self.size)
             else:
                 func = pu.get_subarray_function(other.dtype, self.dtype, result.dtype, pitch = True)
                 func.prepared_call(self._grid, self._block, self.M, self.N, result.gpudata, result.ld, other.gpudata, other.ld, self.gpudata, self.ld)
         return result
     else:
         if other == 0:
             return self
         else:
             if self.size:
                 if self.M == 1:
                     func = pu.get_scalarsub_function(self.dtype, pitch = False)
                     func.prepared_call(self._grid, self._block, self.gpudata, self.gpudata, other, self.size)
                 else:
                     func = pu.get_scalarsub_function(self.dtype, pitch = True)
                     func.prepared_call(self._grid, self._block, self.M, self.N, self.gpudata, self.ld, self.gpudata, self.ld, other)
             return self
示例#2
0
    def __rsub__(self, other):
        if isinstance(other, PitchArray):
            if self.shape != other.shape:
                raise ValueError("array dimension misaligned")
            result = self._new_like_me(_get_common_dtype(self, other))
            if self.size:
                if self.M == 1:
                    func = pu.get_subarray_function(other.dtype,
                                                    self.dtype,
                                                    result.dtype,
                                                    pitch=False)
                    func.prepared_call(self._grid, self._block, result.gpudata,
                                       other.gpudata, self.gpudata, self.size)
                else:
                    func = pu.get_subarray_function(other.dtype,
                                                    self.dtype,
                                                    result.dtype,
                                                    pitch=True)
                    func.prepared_call(self._grid, self._block, self.M, self.N,
                                       result.gpudata, result.ld,
                                       other.gpudata, other.ld, self.gpudata,
                                       self.ld)
            return result
        else:

            result = self._new_like_me()
            if self.size:
                if self.M == 1:
                    func = pu.get_scalarsub_function(self.dtype, pitch=False)
                    func.prepared_call(self._grid, self._block, result.gpudata,
                                       self.gpudata, other, self.size)
                else:
                    func = pu.get_scalarsub_function(self.dtype, pitch=True)
                    func.prepared_call(self._grid, self._block, self.M, self.N,
                                       result.gpudata, result.ld, self.gpudata,
                                       self.ld, other)
            return result
示例#3
0
文件: parray.py 项目: bionet/vtem
 def __rsub__(self, other):
     if isinstance(other, PitchArray):
         if self.shape != other.shape:
             raise ValueError("array dimension misaligned")
         result = self._new_like_me(_get_common_dtype(self, other))
         if self.size:
             if self.M == 1:
                 func = pu.get_subarray_function(other.dtype, self.dtype, result.dtype, pitch = False)
                 func.prepared_call(self._grid, self._block, result.gpudata, other.gpudata, self.gpudata, self.size)
             else:
                 func = pu.get_subarray_function(other.dtype, self.dtype, result.dtype, pitch = True)
                 func.prepared_call(self._grid, self._block, self.M, self.N, result.gpudata, result.ld, other.gpudata, other.ld, self.gpudata, self.ld)
         return result
     else:
     
         result = self._new_like_me()
         if self.size:
             if self.M == 1:
                 func = pu.get_scalarsub_function(self.dtype, pitch = False)
                 func.prepared_call(self._grid, self._block, result.gpudata, self.gpudata, other, self.size)
             else:
                 func = pu.get_scalarsub_function(self.dtype, pitch = True)
                 func.prepared_call(self._grid, self._block, self.M, self.N, result.gpudata, result.ld, self.gpudata, self.ld, other)
         return result