本文整理汇总了Python中cupy.abs方法的典型用法代码示例。如果您正苦于以下问题:Python cupy.abs方法的具体用法?Python cupy.abs怎么用?Python cupy.abs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cupy
的用法示例。
在下文中一共展示了cupy.abs方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import cupy [as 别名]
# 或者: from cupy import abs [as 别名]
def __init__(self, parallel, wave_len=254, wave_dif=64, buffer_size=5, loop_num=5, window=np.hanning(254)):
self.wave_len = wave_len
self.wave_dif = wave_dif
self.buffer_size = buffer_size
self.loop_num = loop_num
self.parallel = parallel
self.window = cp.array([window for _ in range(parallel)])
self.wave_buf = cp.zeros((parallel, wave_len+wave_dif), dtype=float)
self.overwrap_buf = cp.zeros((parallel, wave_dif*buffer_size+(wave_len-wave_dif)), dtype=float)
self.spectrum_buffer = cp.ones((parallel, self.buffer_size, self.wave_len), dtype=complex)
self.absolute_buffer = cp.ones((parallel, self.buffer_size, self.wave_len), dtype=complex)
self.phase = cp.zeros((parallel, self.wave_len), dtype=complex)
self.phase += cp.random.random((parallel, self.wave_len))-0.5 + cp.random.random((parallel, self.wave_len))*1j - 0.5j
self.phase[self.phase == 0] = 1
self.phase /= cp.abs(self.phase)
示例2: test_elementwise_binary
# 需要导入模块: import cupy [as 别名]
# 或者: from cupy import abs [as 别名]
def test_elementwise_binary(self):
desc_a = cutensor.create_tensor_descriptor(self.a, ct.OP_SIGMOID)
desc_c = cutensor.create_tensor_descriptor(self.c, ct.OP_ABS)
d = cutensor.elementwise_binary(
self.alpha, self.a, desc_a, self.mode_a,
self.gamma, self.c, desc_c, self.mode_c,
op_AC=ct.OP_MUL
)
testing.assert_allclose(
self.alpha * (1 / (1 + cupy.exp(-self.a_transposed))) *
self.gamma * cupy.abs(self.c),
d,
rtol=1e-6, atol=1e-6
)
示例3: test_10
# 需要导入模块: import cupy [as 别名]
# 或者: from cupy import abs [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
示例4: test_11
# 需要导入模块: import cupy [as 别名]
# 或者: from cupy import abs [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
示例5: test_01
# 需要导入模块: import cupy [as 别名]
# 或者: from cupy import abs [as 别名]
def test_01(self):
N = 64
K = 5
L = 10
u = cp.random.randn(N, K)
U = cp.dot(u, u.T)
V = cp.random.randn(N, N)
t = cp.sort(cp.abs(V).ravel())[V.size-L]
V[cp.abs(V) < t] = 0
D = U + V
opt = rpca.RobustPCA.Options({'Verbose': False, 'gEvalY': False,
'MaxMainIter': 250,
'AutoRho': {'Enabled': True}})
b = rpca.RobustPCA(D, None, opt)
X, Y = b.solve()
assert sm.mse(U, X) < 5e-6
assert sm.mse(V, Y) < 1e-8
示例6: test_08
# 需要导入模块: import cupy [as 别名]
# 或者: from cupy import abs [as 别名]
def test_08(self):
N = 64
M = 2 * N
L = 4
np.random.seed(12345)
D = cp.array(np.random.randn(N, M))
x0 = cp.zeros((M, 1))
si = cp.array(np.random.permutation(M))
x0[si[0:L]] = cp.array(np.random.randn(L, 1))
s0 = D.dot(x0)
lmbda = 5e-3
opt = bpdn.BPDN.Options({'Verbose': False, 'MaxMainIter': 500,
'RelStopTol': 5e-4})
b = bpdn.BPDN(D, s0, lmbda, opt)
b.solve()
x1 = b.Y
assert cp.abs(b.itstat[-1].ObjFun - 0.012009) < 1e-5
assert cp.abs(b.itstat[-1].DFid - 1.9636082e-06) < 1e-5
assert cp.abs(b.itstat[-1].RegL1 - 2.401446) < 1e-5
assert cp.linalg.norm(x1 - x0) < 1e-3
示例7: test_18
# 需要导入模块: import cupy [as 别名]
# 或者: from cupy import abs [as 别名]
def test_18(self):
N = 64
M = 2 * N
L = 8
cp.random.seed(12345)
D = cp.random.randn(N, M)
x0 = cp.zeros((M, 1))
si = cp.random.permutation(M)
x0[si[0:L]] = cp.random.randn(L, 1)
s = D.dot(x0)
lmbda = 5e-2
opt = bpdn.BPDN.Options({'Verbose': False, 'MaxMainIter': 300,
'RelStopTol': 1e-5, 'AutoRho':
{'Enabled': False}})
bp = bpdn.BPDN(D, s, lmbda=lmbda, opt=opt)
Xp = bp.solve()
epsilon = cp.linalg.norm(D.dot(Xp) - s)
opt = bpdn.MinL1InL2Ball.Options(
{'Verbose': False, 'MaxMainIter': 300, 'RelStopTol': 1e-5,
'rho': 2e1, 'AutoRho': {'Enabled': False}})
bc = bpdn.MinL1InL2Ball(D, s, epsilon=epsilon, opt=opt)
Xc = bc.solve()
assert cp.linalg.norm(Xp - Xc) / cp.linalg.norm(Xp) < 1e-3
assert cp.abs(cp.linalg.norm(Xp, 1) - cp.linalg.norm(Xc, 1)) < 1e-3
示例8: test_10
# 需要导入模块: import cupy [as 别名]
# 或者: from cupy import abs [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
示例9: test_11
# 需要导入模块: import cupy [as 别名]
# 或者: from cupy import abs [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
示例10: inverse
# 需要导入模块: import cupy [as 别名]
# 或者: from cupy import abs [as 别名]
def inverse(self, spectrum, in_phase=None):
if in_phase is None:
in_phase = self.phase
else:
in_phase = cp.array(in_phase)
spectrum = cp.array(spectrum)
self.spectrum_buffer[:, -1] = spectrum * in_phase
self.absolute_buffer[:, -1] = spectrum
for _ in range(self.loop_num):
self.overwrap_buf *= 0
waves = cp.fft.ifft(self.spectrum_buffer, axis=2).real
last = self.spectrum_buffer
for i in range(self.buffer_size):
self.overwrap_buf[:,i*self.wave_dif:i*self.wave_dif+self.wave_len] += waves[:,i]
waves = cp.stack([self.overwrap_buf[:, i*self.wave_dif:i*self.wave_dif+self.wave_len]*self.window for i in range(self.buffer_size)], axis=1)
spectrum = cp.fft.fft(waves, axis=2)
self.spectrum_buffer = self.absolute_buffer * spectrum / (cp.abs(spectrum)+1e-10)
self.spectrum_buffer += 0.5 * (self.spectrum_buffer - last)
dst = cp.asnumpy(self.spectrum_buffer[:, 0])
self.absolute_buffer = cp.roll(self.absolute_buffer, -1, axis=1)
self.spectrum_buffer = cp.roll(self.spectrum_buffer, -1, axis=1)
return dst
示例11: _unwrap_correct
# 需要导入模块: import cupy [as 别名]
# 或者: from cupy import abs [as 别名]
def _unwrap_correct(dd, discont):
ddmod = cupy.mod(dd + numpy.pi, 2*numpy.pi) - numpy.pi
cupy.copyto(ddmod, numpy.pi, where=(ddmod == -numpy.pi) & (dd > 0))
ph_correct = ddmod - dd
cupy.copyto(ph_correct, 0., where=cupy.abs(dd) < discont)
return ph_correct
示例12: _spectrum
# 需要导入模块: import cupy [as 别名]
# 或者: from cupy import abs [as 别名]
def _spectrum(self, x, y):
S = {'x' : cupy.fft.rfft(self._frame(x), self.fftl) / self.norm,
'y' : cupy.fft.rfft(self._frame(y), self.fftl) / self.norm}
A = {'x' : cupy.abs(S['x']),
'y' : cupy.abs(S['y'])}
P = {'x' : cupy.angle(S['x']),
'y' : cupy.angle(S['y'])}
return A, P
示例13: test_22
# 需要导入模块: import cupy [as 别名]
# 或者: from cupy import abs [as 别名]
def test_22(self):
N = 32
M = 4
Nd = 8
D = cp.random.randn(Nd, Nd, M)
D /= cp.sqrt(cp.sum(D**2, axis=(0, 1)))
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-3
opt = cbpdn.ConvBPDN.Options(
{'Verbose': False, 'MaxMainIter': 500, 'RelStopTol': 1e-5,
'rho': 5e-1, 'AutoRho': {'Enabled': False}})
bp = cbpdn.ConvBPDN(D, S, lmbda, opt)
Xp = bp.solve()
epsilon = cp.linalg.norm(bp.reconstruct(Xp).squeeze() - S)
opt = cbpdn.ConvMinL1InL2Ball.Options(
{'Verbose': False, 'MaxMainIter': 500, 'RelStopTol': 1e-5,
'rho': 2e2, 'RelaxParam': 1.0, 'AutoRho': {'Enabled': False}})
bc = cbpdn.ConvMinL1InL2Ball(D, S, epsilon=epsilon, opt=opt)
Xc = bc.solve()
assert cp.linalg.norm(Xp - Xc) / cp.linalg.norm(Xp) < 1e-3
assert cp.abs(cp.linalg.norm(Xp.ravel(), 1) -
cp.linalg.norm(Xc.ravel(), 1)) < 1e-3
示例14: setup_method
# 需要导入模块: import cupy [as 别名]
# 或者: from cupy import abs [as 别名]
def setup_method(self, method):
np.random.seed(12345)
N = 64
L = 20
self.U = cp.ones((N, N))
self.U[:, 0:(old_div(N, 2))] = -1
self.V = cp.asarray(np.random.randn(N, N))
t = cp.sort(cp.abs(self.V).ravel())[self.V.size - L]
self.V[cp.abs(self.V) < t] = 0
self.D = self.U + self.V
示例15: test_01
# 需要导入模块: import cupy [as 别名]
# 或者: from cupy import abs [as 别名]
def test_01(self):
lmbda = 3
opt = tvl1.TVL1Denoise.Options({'Verbose': False, 'gEvalY': False,
'MaxMainIter': 250})
b = tvl1.TVL1Denoise(self.D, lmbda, opt)
X = b.solve()
assert cp.abs(b.itstat[-1].ObjFun - 447.78101756451662) < 1e-6
assert sm.mse(self.U, X) < 1e-6