parray.py 文件源码

python
阅读 41 收藏 0 点赞 0 评论 0

项目:neurodriver 作者: neurokernel 项目源码 文件源码
def __add__(self, other):
        """
        Addition

        Parameters
        ----------
        other: scalar or Pitcharray

        Returns
        -------
        out : PitchArray
            A new PitchArray
        """
        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_addarray_function(
                        self.dtype, other.dtype, result.dtype, pitch = False)
                    func.prepared_call(
                        self._grid, self._block, result.gpudata,
                        self.gpudata, other.gpudata, self.size)
                else:
                    func = pu.get_addarray_function(
                        self.dtype, other.dtype, result.dtype, pitch = True)
                    func.prepared_call(
                        self._grid, self._block, self.M, self.N,
                        result.gpudata, result.ld, self.gpudata,
                        self.ld, other.gpudata, other.ld)
            return result
        elif issubclass(type(other), (float, int, complex, np.integer,
                                      np.floating, np.complexfloating)):
            dtype = _get_common_dtype_with_scalar(other, self)
            if other == 0:
                return self.astype(dtype)
            else:
                result = self._new_like_me(dtype)
                if self.size:
                    if self.M == 1:
                        func = pu.get_addscalar_function(
                            self.dtype, dtype, pitch = False)
                        func.prepared_call(
                            self._grid, self._block, result.gpudata,
                            self.gpudata, other, self.size)
                    else:
                        func = pu.get_addscalar_function(
                            self.dtype, 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
        else:
            raise TypeError("type of object to be added is not supported")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号