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


Python pyfftw.empty_aligned函数代码示例

本文整理汇总了Python中pyfftw.empty_aligned函数的典型用法代码示例。如果您正苦于以下问题:Python empty_aligned函数的具体用法?Python empty_aligned怎么用?Python empty_aligned使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_flags

    def test_flags(self):
        '''Test to see if the flags are correct
        '''
        fft = FFTW(self.input_array, self.output_array)
        self.assertEqual(fft.flags, ('FFTW_MEASURE',))

        fft = FFTW(self.input_array, self.output_array,
                flags=('FFTW_DESTROY_INPUT', 'FFTW_UNALIGNED'))
        self.assertEqual(fft.flags, ('FFTW_DESTROY_INPUT', 'FFTW_UNALIGNED'))

        # Test an implicit flag
        _input_array = empty_aligned(256, dtype='complex64', n=16)
        _output_array = empty_aligned(256, dtype='complex64', n=16)

        # These are guaranteed to be misaligned (due to dtype size == 8)
        input_array = _input_array[:-1]
        output_array = _output_array[:-1]
        u_input_array = _input_array[1:]
        u_output_array = _output_array[1:]

        fft = FFTW(input_array, u_output_array)
        self.assertEqual(fft.flags, ('FFTW_MEASURE', 'FFTW_UNALIGNED'))

        fft = FFTW(u_input_array, output_array)
        self.assertEqual(fft.flags, ('FFTW_MEASURE', 'FFTW_UNALIGNED'))

        fft = FFTW(u_input_array, u_output_array)
        self.assertEqual(fft.flags, ('FFTW_MEASURE', 'FFTW_UNALIGNED'))
开发者ID:carterbox,项目名称:pyFFTW,代码行数:28,代码来源:test_pyfftw_class_misc.py

示例2: generate_wisdom

    def generate_wisdom(self):
        for each_dtype in (numpy.complex128, numpy.complex64, 
                numpy.clongdouble):

            a = empty_aligned((1,1024), each_dtype, n=16)
            b = empty_aligned(a.shape, dtype=a.dtype, n=16)
            fft = FFTW(a,b)
开发者ID:PierreBizouard,项目名称:pyFFTW,代码行数:7,代码来源:test_pyfftw_wisdom.py

示例3: test_update_data_with_unaligned_original

    def test_update_data_with_unaligned_original(self):
        in_shape = self.input_shapes['2d']
        out_shape = self.output_shapes['2d']

        input_dtype_alignment = self.get_input_dtype_alignment()
        
        axes=(-1,)
        a, b = self.create_test_arrays(in_shape, out_shape)

        # Offset from 16 byte aligned to guarantee it's not
        # 16 byte aligned
        a__ = empty_aligned(
                numpy.prod(in_shape)*a.itemsize + input_dtype_alignment,
                dtype='int8', n=16)

        a_ = a__[input_dtype_alignment:].view(dtype=self.input_dtype).reshape(*in_shape)
        a_[:] = a

        b__ = empty_aligned(
                numpy.prod(out_shape)*b.itemsize + input_dtype_alignment,
                dtype='int8', n=16)

        b_ = b__[input_dtype_alignment:].view(dtype=self.output_dtype).reshape(*out_shape)
        b_[:] = b
        
        fft, ifft = self.run_validate_fft(a_, b_, axes, 
                force_unaligned_data=True)
        
        self.run_validate_fft(a, b_, axes, fft=fft, ifft=ifft)
        self.run_validate_fft(a_, b, axes, fft=fft, ifft=ifft)
        self.run_validate_fft(a_, b_, axes, fft=fft, ifft=ifft)
开发者ID:PierreBizouard,项目名称:pyFFTW,代码行数:31,代码来源:test_pyfftw_complex.py

示例4: test_call_with_normalisation_precision

    def test_call_with_normalisation_precision(self):
        '''The normalisation should use a double precision scaling.
        '''
        # Should be the case for double inputs...
        _input_array = empty_aligned((256, 512), dtype='complex128', n=16)

        self.fft()
        ifft = FFTW(self.output_array, _input_array,
                direction='FFTW_BACKWARD')

        ref_output = ifft(normalise_idft=False).copy()/numpy.float64(ifft.N)
        test_output = ifft(normalise_idft=True).copy()

        self.assertTrue(numpy.alltrue(ref_output == test_output))

        # ... and single inputs.
        _input_array = empty_aligned((256, 512), dtype='complex64', n=16)

        ifft = FFTW(numpy.array(self.output_array, _input_array.dtype),
                    _input_array,
                    direction='FFTW_BACKWARD')

        ref_output = ifft(normalise_idft=False).copy()/numpy.float64(ifft.N)
        test_output = ifft(normalise_idft=True).copy()

        self.assertTrue(numpy.alltrue(ref_output == test_output))
开发者ID:grlee77,项目名称:pyFFTW,代码行数:26,代码来源:test_pyfftw_call.py

示例5: test_incorrect_byte_alignment_fails

    def test_incorrect_byte_alignment_fails(self):
        in_shape = self.input_shapes["2d"]
        out_shape = self.output_shapes["2d"]

        input_dtype_alignment = self.get_input_dtype_alignment()

        axes = (-1,)
        a, b = self.create_test_arrays(in_shape, out_shape)

        a = byte_align(a, n=16)
        b = byte_align(b, n=16)

        fft, ifft = self.run_validate_fft(a, b, axes, force_unaligned_data=True)

        a, b = self.create_test_arrays(in_shape, out_shape)

        # Offset from 16 byte aligned to guarantee it's not
        # 16 byte aligned
        a__ = empty_aligned(numpy.prod(in_shape) * a.itemsize + 1, dtype="int8", n=16)

        a_ = a__[1:].view(dtype=self.input_dtype).reshape(*in_shape)
        a_[:] = a

        b__ = empty_aligned(numpy.prod(out_shape) * b.itemsize + 1, dtype="int8", n=16)

        b_ = b__[1:].view(dtype=self.output_dtype).reshape(*out_shape)
        b_[:] = b

        self.assertRaisesRegex(ValueError, "Invalid output alignment", FFTW, *(a, b_))

        self.assertRaisesRegex(ValueError, "Invalid input alignment", FFTW, *(a_, b))

        self.assertRaisesRegex(ValueError, "Invalid input alignment", FFTW, *(a_, b_))
开发者ID:rajath,项目名称:pyFFTW,代码行数:33,代码来源:test_pyfftw_complex.py

示例6: __init__

    def __init__(self,mask, tccList):
        self.mask = mask
        self.tcc = tccList
        self.order = tccList.order
        self.kernelList = tccList.kernelList
        self.coefList = tccList.coefList
        self.focusList = tccList.focusList
        self.focusCoef = tccList.focusCoef
        self.doseList = [1.0]
        self.doseCoef = [1.0]
        self.AIList = []
        self.RIList = []
        self.resist_a = 80
        self.resist_tRef = 0.5

        self.norm = self.mask.y_gridnum*self.mask.x_gridnum
        self.x1 = np.floor(self.mask.x_gridnum/2) - self.tcc.s.fnum
        self.x2 = np.floor(self.mask.x_gridnum/2) + self.tcc.s.fnum  + 1
        self.y1 = np.floor(self.mask.y_gridnum/2) - self.tcc.s.gnum 
        self.y2 = np.floor(self.mask.y_gridnum/2) + self.tcc.s.gnum  + 1

        self.spat_part = pyfftw.empty_aligned((self.mask.y_gridnum,self.mask.x_gridnum),\
                                               dtype='complex128')
        self.freq_part = pyfftw.empty_aligned((self.mask.y_gridnum,self.mask.x_gridnum),\
                                               dtype='complex128')
        self.ifft_image = pyfftw.FFTW(self.freq_part,self.spat_part,axes=(0,1),\
                                     direction='FFTW_BACKWARD')  
开发者ID:vincentlv,项目名称:DimmiLitho,代码行数:27,代码来源:image.py

示例7: test_misaligned_data_doesnt_clobber_cache

    def test_misaligned_data_doesnt_clobber_cache(self):
        '''A bug was highlighted in #197 in which misaligned data causes
        an overwrite of an FFTW internal array which is also the same as
        an output array. The correct behaviour is for the cache to have
        alignment as a key to stop this happening.
        '''
        interfaces.cache.enable()

        N = 64
        pyfftw.interfaces.cache.enable()
        np.random.seed(12345)

        Um = pyfftw.empty_aligned((N, N+1), dtype=np.float32, order='C')
        Vm = pyfftw.empty_aligned((N, N+1), dtype=np.float32, order='C')
        U = np.ndarray((N, N), dtype=Um.dtype, buffer=Um.data, offset=0)
        V = np.ndarray(
            (N, N), dtype=Vm.dtype, buffer=Vm.data, offset=Vm.itemsize)

        U[:] = np.random.randn(N, N).astype(np.float32)
        V[:] = np.random.randn(N, N).astype(np.float32)

        uh = hashlib.md5(U).hexdigest()
        vh = hashlib.md5(V).hexdigest()
        x = interfaces.numpy_fft.rfftn(
            U, None, axes=(0, 1), overwrite_input=False)
        y = interfaces.numpy_fft.rfftn(
            V, None, axes=(0, 1), overwrite_input=False)

        self.assertTrue(uh == hashlib.md5(U).hexdigest())
        self.assertTrue(vh == hashlib.md5(V).hexdigest())

        interfaces.cache.disable()
开发者ID:grlee77,项目名称:pyFFTW,代码行数:32,代码来源:test_pyfftw_interfaces_cache.py

示例8: __init__

 def __init__(self, size):
     self.size = size
     self._time = pyfftw.empty_aligned(size, 'float64')
     self._freq = pyfftw.empty_aligned(size//2 + 1, 'complex128')
     self.fft = pyfftw.FFTW(self._time, self._freq, threads=os.cpu_count(),
                            direction='FFTW_FORWARD')
     self.ifft = pyfftw.FFTW(self._freq, self._time, threads=os.cpu_count(),
                             direction='FFTW_BACKWARD')
开发者ID:crowsonkb,项目名称:fragments,代码行数:8,代码来源:fftw.py

示例9: setUp

    def setUp(self):

        self.input_array = empty_aligned((256, 512), dtype='complex128', n=16)
        self.output_array = empty_aligned((256, 512), dtype='complex128', n=16)

        self.fft = FFTW(self.input_array, self.output_array)

        self.input_array[:] = (numpy.random.randn(*self.input_array.shape)
                + 1j*numpy.random.randn(*self.input_array.shape))
开发者ID:grlee77,项目名称:pyFFTW,代码行数:9,代码来源:test_pyfftw_call.py

示例10: test_call_with_unaligned

    def test_call_with_unaligned(self):
        '''Make sure the right thing happens with unaligned data.
        '''
        input_array = (numpy.random.randn(*self.input_array.shape)
                + 1j*numpy.random.randn(*self.input_array.shape))

        output_array = self.fft(
                input_array=byte_align(input_array.copy(), n=16)).copy()

        input_array = byte_align(input_array, n=16)
        output_array = byte_align(output_array, n=16)

        # Offset by one from 16 byte aligned to guarantee it's not
        # 16 byte aligned
        a = byte_align(input_array.copy(), n=16)
        a__ = empty_aligned(numpy.prod(a.shape)*a.itemsize+1, dtype='int8',
                            n=16)

        a_ = a__[1:].view(dtype=a.dtype).reshape(*a.shape)
        a_[:] = a

        # Create a different second array the same way
        b = byte_align(output_array.copy(), n=16)
        b__ = empty_aligned(numpy.prod(b.shape)*a.itemsize+1, dtype='int8',
                            n=16)

        b_ = b__[1:].view(dtype=b.dtype).reshape(*b.shape)
        b_[:] = a

        # Set up for the first array
        fft = FFTW(input_array, output_array)
        a_[:] = a
        output_array = fft().copy()

        # Check a_ is not aligned...
        self.assertRaisesRegex(ValueError, 'Invalid input alignment',
                self.fft.update_arrays, *(a_, output_array))

        # and b_ too
        self.assertRaisesRegex(ValueError, 'Invalid output alignment',
                self.fft.update_arrays, *(input_array, b_))

        # But it should still work with the a_
        fft(a_)

        # However, trying to update the output will raise an error
        self.assertRaisesRegex(ValueError, 'Invalid output alignment',
                self.fft.update_arrays, *(input_array, b_))

        # Same with SIMD off
        fft = FFTW(input_array, output_array, flags=('FFTW_UNALIGNED',))
        fft(a_)
        self.assertRaisesRegex(ValueError, 'Invalid output alignment',
                self.fft.update_arrays, *(input_array, b_))
开发者ID:grlee77,项目名称:pyFFTW,代码行数:54,代码来源:test_pyfftw_call.py

示例11: pyfftw_container

def pyfftw_container(ny, nx, bwd = False):
    '''
    construct a fftw container to perform fftw.
    '''
    a = pyfftw.empty_aligned((ny,nx),dtype = 'complex128')
    b = pyfftw.empty_aligned((ny,nx),dtype = 'complex128')
    if bwd:
        container = pyfftw.FFTW(a,b,axes = (0,1),direction = 'FFTW_BACKWARD')
    else:
        container = pyfftw.FFTW(a,b,axes = (0,1),direction = 'FFTW_FORWARD')
    return container
开发者ID:danustc,项目名称:Image_toolbox,代码行数:11,代码来源:correlation.py

示例12: test_failure

 def test_failure(self):
     for dtype, npdtype in zip(['32', '64', 'ld'], [np.complex64, np.complex128, np.clongdouble]):
         if dtype == 'ld' and np.dtype(np.clongdouble) == np.dtype(np.complex128):
             # skip this test on systems where clongdouble is complex128
             continue
         if dtype not in _supported_types:
             a = empty_aligned((1,1024), npdtype, n=16)
             b = empty_aligned(a.shape, dtype=a.dtype, n=16)
             msg = "Rebuild pyFFTW with support for %s precision!" % _all_types_human_readable[dtype]
             with self.assertRaisesRegex(NotImplementedError, msg):
                 FFTW(a,b)
开发者ID:grlee77,项目名称:pyFFTW,代码行数:11,代码来源:test_pyfftw_partial.py

示例13: test_update_data_with_alignment_error

    def test_update_data_with_alignment_error(self):
        in_shape = self.input_shapes['2d']
        out_shape = self.output_shapes['2d']

        byte_error = 1
        
        axes=(-1,)
        a, b = self.create_test_arrays(in_shape, out_shape)

        a = byte_align(a, n=16)
        b = byte_align(b, n=16)

        fft, ifft = self.run_validate_fft(a, b, axes)
        
        a, b = self.create_test_arrays(in_shape, out_shape)

        # Offset from 16 byte aligned to guarantee it's not
        # 16 byte aligned
        a__ = empty_aligned(
                numpy.prod(in_shape)*a.itemsize+byte_error,
                dtype='int8', n=16)

        a_ = (a__[byte_error:]
                .view(dtype=self.input_dtype).reshape(*in_shape))
        a_[:] = a

        b__ = empty_aligned(
                numpy.prod(out_shape)*b.itemsize+byte_error,
                dtype='int8', n=16)

        b_ = (b__[byte_error:]
                .view(dtype=self.output_dtype).reshape(*out_shape))
        b_[:] = b
     
        with self.assertRaisesRegex(ValueError, 'Invalid output alignment'):
            self.run_validate_fft(a, b_, axes, fft=fft, ifft=ifft, 
                    create_array_copies=False)

        with self.assertRaisesRegex(ValueError, 'Invalid input alignment'):
            self.run_validate_fft(a_, b, axes, fft=fft, ifft=ifft, 
                    create_array_copies=False)

        # Should also be true for the unaligned case
        fft, ifft = self.run_validate_fft(a, b, axes, 
                force_unaligned_data=True)

        with self.assertRaisesRegex(ValueError, 'Invalid output alignment'):
            self.run_validate_fft(a, b_, axes, fft=fft, ifft=ifft, 
                    create_array_copies=False)

        with self.assertRaisesRegex(ValueError, 'Invalid input alignment'):
            self.run_validate_fft(a_, b, axes, fft=fft, ifft=ifft, 
                    create_array_copies=False)
开发者ID:PierreBizouard,项目名称:pyFFTW,代码行数:53,代码来源:test_pyfftw_complex.py

示例14: test_is_byte_aligned

    def test_is_byte_aligned(self):
        a = empty_aligned(100)
        self.assertTrue(is_byte_aligned(a, get_expected_alignment(None)))

        a = empty_aligned(100, n=16)
        self.assertTrue(is_byte_aligned(a, n=16))

        a = empty_aligned(100, n=5)
        self.assertTrue(is_byte_aligned(a, n=5))

        a = empty_aligned(100, dtype="float32", n=16)[1:]
        self.assertFalse(is_byte_aligned(a, n=16))
        self.assertTrue(is_byte_aligned(a, n=4))
开发者ID:rajath,项目名称:pyFFTW,代码行数:13,代码来源:test_pyfftw_nbyte_align.py

示例15: get_fft

 def get_fft(self):
     try:
         import pyfftw
         if not hasattr(self,'__fftw_ffts'):
             a = pyfftw.empty_aligned((self._nx, self._ny), dtype='complex128')
             b = pyfftw.empty_aligned((self._nx, self._ny), dtype='complex128')
             fft2 = pyfftw.FFTW(a, b, axes=(0,1), threads=self._thread_count, direction = 'FFTW_FORWARD')
             ifft2 = pyfftw.FFTW(b, a, axes=(0,1), threads=self._thread_count, direction = 'FFTW_BACKWARD')
             self.__fftw_ffts = fft2,ifft2
         return self.__fftw_ffts
     except ImportError:
         from numpy.fft import fft2,ifft2
         return fft2,ifft2
开发者ID:TheLartians,项目名称:PyPropagate,代码行数:13,代码来源:fresnel.py


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