本文整理汇总了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)
示例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)
示例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)
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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)
示例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)
示例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)
示例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)
示例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