• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python pyfftw.byte_align函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_update_unaligned_data_with_FFTW_UNALIGNED

    def test_update_unaligned_data_with_FFTW_UNALIGNED(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 + 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

        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:rajath,项目名称:pyFFTW,代码行数:31,代码来源:test_pyfftw_complex.py


示例2: 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


示例3: 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


示例4: 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


示例5: test_call_with_keyword_output_update

    def test_call_with_keyword_output_update(self):
        """Test the class call with a keyword output update.
        """
        output_array = byte_align(
            (numpy.random.randn(*self.output_array.shape) + 1j * numpy.random.randn(*self.output_array.shape)), n=16
        )

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

        self.fft.update_arrays(self.input_array, output_array)
        self.fft.execute()

        self.assertTrue(numpy.alltrue(returned_output_array == output_array))
开发者ID:rajath,项目名称:pyFFTW,代码行数:13,代码来源:test_pyfftw_call.py


示例6: test_call_with_keyword_input_update

    def test_call_with_keyword_input_update(self):
        """Test the class call with a keyword input update.
        """
        input_array = byte_align(
            numpy.random.randn(*self.input_array.shape) + 1j * numpy.random.randn(*self.input_array.shape), n=16
        )

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

        self.fft.update_arrays(input_array, self.output_array)
        self.fft.execute()

        self.assertTrue(numpy.alltrue(output_array == self.output_array))
开发者ID:rajath,项目名称:pyFFTW,代码行数:13,代码来源:test_pyfftw_call.py


示例7: test_call_with_positional_input_update

    def test_call_with_positional_input_update(self):
        '''Test the class call with a positional input update.
        '''

        input_array = byte_align(
                (numpy.random.randn(*self.input_array.shape)
                    + 1j*numpy.random.randn(*self.input_array.shape)), n=16)

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

        self.fft.update_arrays(input_array, self.output_array)
        self.fft.execute()

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


示例8: test_byte_align_consistent_data

    def test_byte_align_consistent_data(self):
        shape = (10, 10)
        a = numpy.int16(numpy.random.randn(*shape) * 16000)
        b = numpy.float64(numpy.random.randn(*shape))
        c = numpy.int8(numpy.random.randn(*shape) * 255)

        # Test a few alignments
        for n in [None, 3, 7, 9, 16, 24, 23, 63, 64]:
            d = byte_align(a, n=n)
            self.assertTrue(numpy.array_equal(a, d))

            d = byte_align(b, n=n)
            self.assertTrue(numpy.array_equal(b, d))

            d = byte_align(c, n=n)
            self.assertTrue(numpy.array_equal(c, d))
开发者ID:rajath,项目名称:pyFFTW,代码行数:16,代码来源:test_pyfftw_nbyte_align.py


示例9: test_avoid_copy

    def test_avoid_copy(self):
        '''Test the avoid_copy flag
        '''
        dtype_tuple = input_dtypes[functions[self.func]]
        
        for dtype in dtype_tuple[0]:
            for test_shape, s, kwargs in self.test_data:
                _kwargs = kwargs.copy()

                _kwargs['avoid_copy'] = True

                s2 = copy.copy(s)
                try:
                    for each_axis, length in enumerate(s):
                        s2[each_axis] += 2
                except TypeError:
                    s2 += 2

                input_array = dtype_tuple[1](test_shape, dtype)

                self.assertRaisesRegex(ValueError, 
                        'Cannot avoid copy.*transform shape.*',
                        getattr(builders, self.func),
                        input_array, s2, **_kwargs)

                non_contiguous_shape = [
                        each_dim * 2 for each_dim in test_shape]
                non_contiguous_slices = (
                        [slice(None, None, 2)] * len(test_shape))

                misaligned_input_array = dtype_tuple[1](
                        non_contiguous_shape, dtype)[non_contiguous_slices]

                self.assertRaisesRegex(ValueError, 
                        'Cannot avoid copy.*not contiguous.*',
                        getattr(builders, self.func),
                        misaligned_input_array, s, **_kwargs)

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

                misaligned_input_array = _input_array[1:].view(
                         dtype=input_array.dtype).reshape(*test_shape)

                self.assertRaisesRegex(ValueError, 
                        'Cannot avoid copy.*not aligned.*',
                        getattr(builders, self.func),
                        misaligned_input_array, s, **_kwargs)

                _input_array = byte_align(input_array.copy())
                FFTW_object = getattr(builders, self.func)(
                        _input_array, s, **_kwargs)

                # A catch all to make sure the internal array
                # is not a copy
                self.assertTrue(FFTW_object.input_array is
                        _input_array)
开发者ID:ng110,项目名称:pyFFTW,代码行数:60,代码来源:test_pyfftw_builders.py


示例10: test_call_with_different_input_dtype

    def test_call_with_different_input_dtype(self):
        '''Test the class call with an array with a different input dtype
        '''
        input_array = byte_align(numpy.complex64(
                numpy.random.randn(*self.input_array.shape)
                + 1j*numpy.random.randn(*self.input_array.shape)))

        output_array = self.fft(byte_align(input_array.copy())).copy()

        _input_array = numpy.asarray(input_array,
                dtype=self.input_array.dtype)

        self.update_arrays(_input_array, self.output_array)
        self.fft.execute()

        self.assertTrue(numpy.alltrue(output_array == self.output_array))
开发者ID:ng110,项目名称:pyFFTW,代码行数:16,代码来源:test_pyfftw_builders.py


示例11: test_call_with_different_striding

    def test_call_with_different_striding(self):
        '''Test the input update with different strides to internal array.
        '''
        input_array_shape = self.input_array.shape + (2,)
        internal_array_shape = self.internal_array.shape

        internal_array = byte_align(
                numpy.random.randn(*internal_array_shape)
                + 1j*numpy.random.randn(*internal_array_shape))

        fft =  utils._FFTWWrapper(internal_array, self.output_array,
                input_array_slicer=self.input_array_slicer,
                FFTW_array_slicer=self.FFTW_array_slicer)

        test_output_array = fft().copy()

        new_input_array = empty_aligned(input_array_shape,
                                        dtype=internal_array.dtype)
        new_input_array[:] = 0

        new_input_array[:,:,0][self.input_array_slicer] = (
                internal_array[self.FFTW_array_slicer])

        new_output = fft(new_input_array[:,:,0]).copy()

        # Test the test!
        self.assertTrue(
                new_input_array[:,:,0].strides != internal_array.strides)

        self.assertTrue(numpy.alltrue(test_output_array == new_output))
开发者ID:ng110,项目名称:pyFFTW,代码行数:30,代码来源:test_pyfftw_builders.py


示例12: test_byte_align_integer_shape

 def test_byte_align_integer_shape(self):
     shape = 100
     a = numpy.random.randn(shape)
     # Test a few alignments
     for n in [None, 3, 7, 9, 16, 24, 23, 63, 64]:
         expected_alignment = get_expected_alignment(n)
         b = byte_align(a, n=n)
         self.assertTrue(b.ctypes.data % expected_alignment == 0)
开发者ID:rajath,项目名称:pyFFTW,代码行数:8,代码来源:test_pyfftw_nbyte_align.py


示例13: test_call_with_positional_updates

    def test_call_with_positional_updates(self):
        '''Test the class call with a positional array updates.
        '''

        input_array = byte_align((numpy.random.randn(*self.input_array.shape)
            + 1j*numpy.random.randn(*self.input_array.shape)))

        output_array = byte_align((numpy.random.randn(*self.output_array.shape)
            + 1j*numpy.random.randn(*self.output_array.shape)))

        returned_output_array = self.fft(
            byte_align(input_array.copy()),
            byte_align(output_array.copy())).copy()

        self.update_arrays(input_array, output_array)
        self.fft.execute()

        self.assertTrue(numpy.alltrue(returned_output_array == output_array))
开发者ID:ng110,项目名称:pyFFTW,代码行数:18,代码来源:test_pyfftw_builders.py


示例14: test_call_with_invalid_output_striding

    def test_call_with_invalid_output_striding(self):
        '''Test the class call with an invalid strided output update.
        '''
        # Add an extra dimension to bugger up the striding
        new_shape = self.output_array.shape + (2,)
        output_array = byte_align(numpy.random.randn(*new_shape)
                + 1j*numpy.random.randn(*new_shape))

        self.assertRaisesRegex(ValueError, 'Invalid output striding',
                self.fft, **{'output_array': output_array[:,:,1]})
开发者ID:ng110,项目名称:pyFFTW,代码行数:10,代码来源:test_pyfftw_builders.py


示例15: test_byte_align_set_dtype

    def test_byte_align_set_dtype(self):
        shape = (10, 10)
        a = numpy.int16(numpy.random.randn(*shape) * 16000)
        b = numpy.float64(numpy.random.randn(*shape))
        c = numpy.int8(numpy.random.randn(*shape) * 255)
        # Test a few alignments
        for n in [None, 3, 7, 9, 16, 24, 23, 63, 64]:
            expected_alignment = get_expected_alignment(n)
            d = byte_align(a, dtype="float32", n=n)
            self.assertTrue(d.ctypes.data % expected_alignment == 0)
            self.assertTrue(d.dtype == "float32")

            d = byte_align(b, dtype="float32", n=n)
            self.assertTrue(d.ctypes.data % expected_alignment == 0)
            self.assertTrue(d.dtype == "float32")

            d = byte_align(c, dtype="float64", n=n)
            self.assertTrue(d.ctypes.data % expected_alignment == 0)
            self.assertTrue(d.dtype == "float64")
开发者ID:rajath,项目名称:pyFFTW,代码行数:19,代码来源:test_pyfftw_nbyte_align.py


示例16: test_call_with_different_striding

    def test_call_with_different_striding(self):
        """Test the input update with different strides to internal array.
        """
        shape = self.input_array.shape + (2,)

        input_array = byte_align(numpy.random.randn(*shape) + 1j * numpy.random.randn(*shape), n=16)

        fft = FFTW(input_array[:, :, 0], self.output_array)

        test_output_array = fft().copy()

        new_input_array = byte_align(input_array[:, :, 0].copy(), n=16)

        new_output = fft(new_input_array).copy()

        # Test the test!
        self.assertTrue(new_input_array.strides != input_array[:, :, 0].strides)

        self.assertTrue(numpy.alltrue(test_output_array == new_output))
开发者ID:rajath,项目名称:pyFFTW,代码行数:19,代码来源:test_pyfftw_call.py


示例17: test_byte_align_different_dtypes

    def test_byte_align_different_dtypes(self):
        shape = (10, 10)
        a = numpy.int16(numpy.random.randn(*shape) * 16000)
        b = numpy.float64(numpy.random.randn(*shape))
        c = numpy.int8(numpy.random.randn(*shape) * 255)
        # Test a few alignments
        for n in [None, 3, 7, 9, 16, 24, 23, 63, 64]:
            expected_alignment = get_expected_alignment(n)
            d = byte_align(a, n=n)
            self.assertTrue(d.ctypes.data % expected_alignment == 0)
            self.assertTrue(d.__class__ == a.__class__)

            d = byte_align(b, n=n)
            self.assertTrue(d.ctypes.data % expected_alignment == 0)
            self.assertTrue(d.__class__ == b.__class__)

            d = byte_align(c, n=n)
            self.assertTrue(d.ctypes.data % expected_alignment == 0)
            self.assertTrue(d.__class__ == c.__class__)
开发者ID:rajath,项目名称:pyFFTW,代码行数:19,代码来源:test_pyfftw_nbyte_align.py


示例18: test_call_with_copy_with_missized_array_error

    def test_call_with_copy_with_missized_array_error(self):
        '''Force an input copy with a missized array.
        '''
        shape = list(self.input_array.shape + (2,))
        shape[0] += 1

        input_array = byte_align(numpy.random.randn(*shape)
                + 1j*numpy.random.randn(*shape))

        self.assertRaisesRegex(ValueError, 'Invalid input shape',
                self.fft, **{'input_array': input_array[:,:,0]})
开发者ID:ng110,项目名称:pyFFTW,代码行数:11,代码来源:test_pyfftw_builders.py


示例19: test_call_with_copy_with_missized_array_error

    def test_call_with_copy_with_missized_array_error(self):
        """Force an input copy with a missized array.
        """
        shape = list(self.input_array.shape + (2,))
        shape[0] += 1

        input_array = byte_align(numpy.random.randn(*shape) + 1j * numpy.random.randn(*shape), n=16)

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

        self.assertRaisesRegex(ValueError, "Invalid input shape", self.fft, **{"input_array": input_array[:, :, 0]})
开发者ID:rajath,项目名称:pyFFTW,代码行数:11,代码来源:test_pyfftw_call.py


示例20: test_call_with_auto_input_alignment

    def test_call_with_auto_input_alignment(self):
        '''Test the class call with a keyword input update.
        '''
        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()

        # Offset by one from 16 byte aligned to guarantee it's not
        # 16 byte aligned
        a = input_array
        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

        # Just confirm that a usual update will fail
        self.assertRaisesRegex(ValueError, 'Invalid input alignment',
                self.fft.update_arrays, *(a_, self.output_array))

        self.fft(a_, self.output_array)

        self.assertTrue(numpy.alltrue(output_array == self.output_array))

        # now try with a single byte offset and SIMD off
        ar, ai = numpy.float32(numpy.random.randn(2, 257))
        a = ar[1:] + 1j*ai[1:]

        b = a.copy()

        a_size = len(a.ravel())*a.itemsize

        update_array = numpy.frombuffer(
                numpy.zeros(a_size + 1, dtype='int8')[1:].data,
                dtype=a.dtype).reshape(a.shape)

        fft = FFTW(a, b, flags=('FFTW_UNALIGNED',))
        # Confirm that a usual update will fail (it's not on the
        # byte boundary)
        self.assertRaisesRegex(ValueError, 'Invalid input alignment',
                fft.update_arrays, *(update_array, b))

        fft(update_array, b)
开发者ID:grlee77,项目名称:pyFFTW,代码行数:45,代码来源:test_pyfftw_call.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pyfftw.empty_aligned函数代码示例发布时间:2022-05-25
下一篇:
Python utils.root函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap