def run_test_c2r_impl(self, shape, axes, fftshift=False):
ishape = list(shape)
oshape = list(shape)
ishape[axes[-1]] = shape[axes[-1]] // 2 + 1
oshape[axes[-1]] = (ishape[axes[-1]] - 1) * 2
ishape[-1] *= 2 # For complex
known_data = np.random.normal(size=ishape).astype(np.float32).view(np.complex64)
idata = bf.ndarray(known_data, space='cuda')
odata = bf.ndarray(shape=oshape, dtype='f32', space='cuda')
fft = Fft()
fft.init(idata, odata, axes=axes, apply_fftshift=fftshift)
fft.execute(idata, odata)
# Note: Numpy applies normalization while CUFFT does not
norm = reduce(lambda a, b: a * b, [shape[d] for d in axes])
if fftshift:
known_data = np.fft.ifftshift(known_data, axes=axes)
known_result = gold_irfftn(known_data, axes=axes) * norm
compare(odata.copy('system'), known_result)
python类irfftn()的实例源码
def test_not_last_axis_success(self):
ar, ai = np.random.random((2, 16, 8, 32))
a = ar + 1j*ai
axes = (-2,)
# Should not raise error
fft.irfftn(a, axes=axes)
def compute(a, b):
"""
Compute an optimal displacement between two ndarrays.
Finds the displacement between two ndimensional arrays. Arrays must be
of the same size. Algorithm uses a cross correlation, computed efficiently
through an n-dimensional fft.
Parameters
----------
a : ndarray
The first array
b : ndarray
The second array
"""
from numpy.fft import rfftn, irfftn
from numpy import unravel_index, argmax
# compute real-valued cross-correlation in fourier domain
s = a.shape
f = rfftn(a)
f *= rfftn(b).conjugate()
c = abs(irfftn(f, s))
# find location of maximum
inds = unravel_index(argmax(c), s)
# fix displacements that are greater than half the total size
pairs = zip(inds, a.shape)
# cast to basic python int for serialization
adjusted = [int(d - n) if d > n // 2 else int(d) for (d, n) in pairs]
return Displacement(adjusted)
def test_not_last_axis_success(self):
ar, ai = np.random.random((2, 16, 8, 32))
a = ar + 1j*ai
axes = (-2,)
# Should not raise error
fft.irfftn(a, axes=axes)
test_helper.py 文件源码
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda
作者: SignalMedia
项目源码
文件源码
阅读 24
收藏 0
点赞 0
评论 0
def test_not_last_axis_success(self):
ar, ai = np.random.random((2, 16, 8, 32))
a = ar + 1j*ai
axes = (-2,)
# Should not raise error
fft.irfftn(a, axes=axes)
def test_not_last_axis_success(self):
ar, ai = np.random.random((2, 16, 8, 32))
a = ar + 1j*ai
axes = (-2,)
# Should not raise error
fft.irfftn(a, axes=axes)
def test_not_last_axis_success(self):
ar, ai = np.random.random((2, 16, 8, 32))
a = ar + 1j*ai
axes = (-2,)
# Should not raise error
fft.irfftn(a, axes=axes)
def test_not_last_axis_success(self):
ar, ai = np.random.random((2, 16, 8, 32))
a = ar + 1j*ai
axes = (-2,)
# Should not raise error
fft.irfftn(a, axes=axes)
def test_not_last_axis_success(self):
ar, ai = np.random.random((2, 16, 8, 32))
a = ar + 1j*ai
axes = (-2,)
# Should not raise error
fft.irfftn(a, axes=axes)