当前位置: 首页>>代码示例>>Python>>正文


Python cupy.sum方法代码示例

本文整理汇总了Python中cupy.sum方法的典型用法代码示例。如果您正苦于以下问题:Python cupy.sum方法的具体用法?Python cupy.sum怎么用?Python cupy.sum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cupy的用法示例。


在下文中一共展示了cupy.sum方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: cumsum

# 需要导入模块: import cupy [as 别名]
# 或者: from cupy import sum [as 别名]
def cumsum(a, axis=None, dtype=None, out=None):
    """Returns the cumulative sum of an array along a given axis.

    Args:
        a (cupy.ndarray): Input array.
        axis (int): Axis along which the cumulative sum is taken. If it is not
            specified, the input is flattened.
        dtype: Data type specifier.
        out (cupy.ndarray): Output array.

    Returns:
        cupy.ndarray: The result array.

    .. seealso:: :func:`numpy.cumsum`

    """
    return _math.scan_core(a, axis, _math.scan_op.SCAN_SUM, dtype, out) 
开发者ID:cupy,项目名称:cupy,代码行数:19,代码来源:sumprod.py

示例2: matrix_rank

# 需要导入模块: import cupy [as 别名]
# 或者: from cupy import sum [as 别名]
def matrix_rank(M, tol=None):
    """Return matrix rank of array using SVD method

    Args:
        M (cupy.ndarray): Input array. Its `ndim` must be less than or equal to
            2.
        tol (None or float): Threshold of singular value of `M`.
            When `tol` is `None`, and `eps` is the epsilon value for datatype
            of `M`, then `tol` is set to `S.max() * max(M.shape) * eps`,
            where `S` is the singular value of `M`.
            It obeys :func:`numpy.linalg.matrix_rank`.

    Returns:
        cupy.ndarray: Rank of `M`.

    .. seealso:: :func:`numpy.linalg.matrix_rank`
    """
    if M.ndim < 2:
        return (M != 0).any().astype(int)
    S = decomposition.svd(M, compute_uv=False)
    if tol is None:
        tol = (S.max(axis=-1, keepdims=True) * max(M.shape[-2:]) *
               numpy.finfo(S.dtype).eps)
    return (S > tol).sum(axis=-1, dtype=numpy.intp) 
开发者ID:cupy,项目名称:cupy,代码行数:26,代码来源:norms.py

示例3: trace

# 需要导入模块: import cupy [as 别名]
# 或者: from cupy import sum [as 别名]
def trace(a, offset=0, axis1=0, axis2=1, dtype=None, out=None):
    """Returns the sum along the diagonals of an array.

    It computes the sum along the diagonals at ``axis1`` and ``axis2``.

    Args:
        a (cupy.ndarray): Array to take trace.
        offset (int): Index of diagonals. Zero indicates the main diagonal, a
            positive value an upper diagonal, and a negative value a lower
            diagonal.
        axis1 (int): The first axis along which the trace is taken.
        axis2 (int): The second axis along which the trace is taken.
        dtype: Data type specifier of the output.
        out (cupy.ndarray): Output array.

    Returns:
        cupy.ndarray: The trace of ``a`` along axes ``(axis1, axis2)``.

    .. seealso:: :func:`numpy.trace`

    """
    # TODO(okuta): check type
    return a.trace(offset, axis1, axis2, dtype, out) 
开发者ID:cupy,项目名称:cupy,代码行数:25,代码来源:norms.py

示例4: dirichlet

# 需要导入模块: import cupy [as 别名]
# 或者: from cupy import sum [as 别名]
def dirichlet(self, alpha, size=None, dtype=float):
        """Returns an array of samples drawn from the dirichlet distribution.

        .. seealso::
            :func:`cupy.random.dirichlet` for full documentation,
            :meth:`numpy.random.RandomState.dirichlet
            <numpy.random.mtrand.RandomState.dirichlet>`
        """
        alpha = cupy.asarray(alpha)
        if size is None:
            size = alpha.shape
        else:
            size += alpha.shape
        y = cupy.empty(shape=size, dtype=dtype)
        _kernels.standard_gamma_kernel(alpha, self._rk_seed, y)
        y /= y.sum(axis=-1, keepdims=True)
        self._update_seed(y.size)
        return y 
开发者ID:cupy,项目名称:cupy,代码行数:20,代码来源:generator.py

示例5: test_10

# 需要导入模块: import cupy [as 别名]
# 或者: from cupy import sum [as 别名]
def test_10(self):
        N = 64
        M = 4
        Nd = 8
        D = cp.random.randn(Nd, Nd, M)
        X0 = cp.zeros((N, N, M))
        xr = cp.random.randn(N, N, M)
        xp = cp.abs(xr) > 3
        X0[xp] = cp.random.randn(X0[xp].size)
        S = cp.sum(fftconv(D, X0), axis=2)
        lmbda = 1e-4
        rho = 1e-1
        opt = cbpdn.ConvBPDN.Options({'Verbose': False, 'MaxMainIter': 500,
                                      'RelStopTol': 1e-3, 'rho': rho,
                                      'AutoRho': {'Enabled': False}})
        b = cbpdn.ConvBPDN(D, S, lmbda, opt)
        b.solve()
        X1 = b.Y.squeeze()
        assert rrs(X0, X1) < 5e-5
        Sr = b.reconstruct().squeeze()
        assert rrs(S, Sr) < 1e-4 
开发者ID:bwohlberg,项目名称:sporco,代码行数:23,代码来源:test_cbpdn.py

示例6: test_11

# 需要导入模块: import cupy [as 别名]
# 或者: from cupy import sum [as 别名]
def test_11(self):
        N = 63
        M = 4
        Nd = 8
        D = cp.random.randn(Nd, Nd, M)
        X0 = cp.zeros((N, N, M))
        xr = cp.random.randn(N, N, M)
        xp = cp.abs(xr) > 3
        X0[xp] = cp.random.randn(X0[xp].size)
        S = cp.sum(ifftn(fftn(D, (N, N), (0, 1)) *
                         fftn(X0, None, (0, 1)), None, (0, 1)).real,
                   axis=2)
        lmbda = 1e-4
        rho = 1e-1
        opt = cbpdn.ConvBPDN.Options({'Verbose': False, 'MaxMainIter': 500,
                                      'RelStopTol': 1e-3, 'rho': rho,
                                      'AutoRho': {'Enabled': False}})
        b = cbpdn.ConvBPDN(D, S, lmbda, opt)
        b.solve()
        X1 = b.Y.squeeze()
        assert rrs(X0, X1) < 5e-5
        Sr = b.reconstruct().squeeze()
        assert rrs(S, Sr) < 1e-4 
开发者ID:bwohlberg,项目名称:sporco,代码行数:25,代码来源:test_cbpdn.py

示例7: test_12

# 需要导入模块: import cupy [as 别名]
# 或者: from cupy import sum [as 别名]
def test_12(self):
        rho = 1e-1
        N = 32
        M = 16
        C = 3
        K = 8
        D = signal.complex_randn(N, N, C, 1, M)
        X = signal.complex_randn(N, N, 1, K, M)
        S = cp.sum(D*X, axis=4, keepdims=True)

        Xop = lambda x: cp.sum(X * x, axis=4, keepdims=True)
        XHop = lambda x: cp.sum(cp.conj(X)* x, axis=3, keepdims=True)
        Z = (XHop(Xop(D)) + rho*D - XHop(S)) / rho
        Dslv = linalg.solvemdbi_ism(X, rho, XHop(S) + rho*Z, 4, 3)

        assert linalg.rrs(XHop(Xop(Dslv)) + rho*Dslv, XHop(S) + rho*Z) < 1e-11 
开发者ID:bwohlberg,项目名称:sporco,代码行数:18,代码来源:test_linalg.py

示例8: test_14

# 需要导入模块: import cupy [as 别名]
# 或者: from cupy import sum [as 别名]
def test_14(self):
        rho = 1e-1
        N = 64
        M = 32
        C = 3
        K = 8
        D = signal.complex_randn(N, N, C, 1, M)
        X = signal.complex_randn(N, N, 1, K, M)
        S = cp.sum(D*X, axis=4, keepdims=True)

        Xop = lambda x: cp.sum(X * x, axis=4, keepdims=True)
        XHop = lambda x: cp.sum(cp.conj(X) * x, axis=3, keepdims=True)
        Z = (XHop(Xop(D)) + rho*D - XHop(S)) / rho
        Dslv = linalg.solvemdbi_rsm(X, rho, XHop(S) + rho*Z, 3)

        assert linalg.rrs(XHop(Xop(Dslv)) + rho*Dslv, XHop(S) + rho*Z) < 1e-11 
开发者ID:bwohlberg,项目名称:sporco,代码行数:18,代码来源:test_linalg.py

示例9: test_10

# 需要导入模块: import cupy [as 别名]
# 或者: from cupy import sum [as 别名]
def test_10(self):
        N = 64
        M = 4
        Nd = 8
        D = cp.random.randn(Nd, Nd, M)
        X0 = cp.zeros((N, N, M))
        xr = cp.random.randn(N, N, M)
        xp = cp.abs(xr) > 3
        X0[xp] = cp.random.randn(X0[xp].size)
        S = cp.sum(ifftn(fftn(D, (N, N), (0, 1)) *
                            fftn(X0, None, (0, 1)), None, (0, 1)).real,
                   axis=2)
        lmbda = 1e-2
        L = 1e3
        opt = cbpdn.ConvBPDN.Options({'Verbose': False, 'MaxMainIter': 2000,
                                      'RelStopTol': 1e-9, 'L': L,
                                      'BackTrack': {'Enabled': False}})
        b = cbpdn.ConvBPDN(D, S, lmbda, opt)
        b.solve()
        X1 = b.X.squeeze()
        assert rrs(X0, X1) < 5e-4
        Sr = b.reconstruct().squeeze()
        assert rrs(S, Sr) < 3e-4 
开发者ID:bwohlberg,项目名称:sporco,代码行数:25,代码来源:test_cbpdn.py

示例10: test_11

# 需要导入模块: import cupy [as 别名]
# 或者: from cupy import sum [as 别名]
def test_11(self):
        N = 63
        M = 4
        Nd = 8
        D = cp.random.randn(Nd, Nd, M)
        X0 = cp.zeros((N, N, M))
        xr = cp.random.randn(N, N, M)
        xp = cp.abs(xr) > 3
        X0[xp] = cp.random.randn(X0[xp].size)
        S = cp.sum(ifftn(fftn(D, (N, N), (0, 1)) *
                         fftn(X0, None, (0, 1)), None, (0, 1)).real,
                   axis=2)
        lmbda = 1e-2
        L = 1e3
        opt = cbpdn.ConvBPDN.Options({'Verbose': False, 'MaxMainIter': 2000,
                                      'RelStopTol': 1e-9, 'L': L,
                                      'BackTrack': {'Enabled': False}})
        b = cbpdn.ConvBPDN(D, S, lmbda, opt)
        b.solve()
        X1 = b.X.squeeze()
        assert rrs(X0, X1) < 5e-4
        Sr = b.reconstruct().squeeze()
        assert rrs(S, Sr) < 2e-4 
开发者ID:bwohlberg,项目名称:sporco,代码行数:25,代码来源:test_cbpdn.py

示例11: test_sum_axis

# 需要导入模块: import cupy [as 别名]
# 或者: from cupy import sum [as 别名]
def test_sum_axis(self, xp):
        return lambda x: cupy.sum(x, self.axis) 
开发者ID:cupy,项目名称:cupy,代码行数:4,代码来源:test_reduction.py

示例12: test_sum_kwargs_axis

# 需要导入模块: import cupy [as 别名]
# 或者: from cupy import sum [as 别名]
def test_sum_kwargs_axis(self, xp):
        return lambda x: cupy.sum(x, axis=self.axis) 
开发者ID:cupy,项目名称:cupy,代码行数:4,代码来源:test_reduction.py

示例13: test_premap_one_array

# 需要导入模块: import cupy [as 别名]
# 或者: from cupy import sum [as 别名]
def test_premap_one_array(self, xp):
        return lambda x, y: xp.sum(x * 3, self.axis) 
开发者ID:cupy,项目名称:cupy,代码行数:4,代码来源:test_reduction.py

示例14: test_premap_two_arrays

# 需要导入模块: import cupy [as 别名]
# 或者: from cupy import sum [as 别名]
def test_premap_two_arrays(self, xp):
        return lambda x, y: xp.sum(x + y, self.axis) 
开发者ID:cupy,项目名称:cupy,代码行数:4,代码来源:test_reduction.py

示例15: test_postmap_one_array

# 需要导入模块: import cupy [as 别名]
# 或者: from cupy import sum [as 别名]
def test_postmap_one_array(self, xp):
        return lambda x, y: xp.sum(x, self.axis) + 3 
开发者ID:cupy,项目名称:cupy,代码行数:4,代码来源:test_reduction.py


注:本文中的cupy.sum方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。