<s> """<STR_LIT>""" <EOL> from __future__ import division <EOL> from unittest import main , makeSuite , TestCase , TestSuite <EOL> import pycuda . autoinit <EOL> import pycuda . driver as drv <EOL> import pycuda . gpuarray as gpuarray <EOL> import numpy as np <EOL> import skcuda . fft as fft <EOL> import skcuda . misc as misc <EOL> atol_float32 = <NUM_LIT> <EOL> atol_float64 = <NUM_LIT> <EOL> class test_fft ( TestCase ) : <EOL> def setUp ( self ) : <EOL> np . random . seed ( <NUM_LIT:0> ) <EOL> self . N = <NUM_LIT:8> <EOL> self . M = <NUM_LIT:4> <EOL> self . B = <NUM_LIT:3> <EOL> def test_fft_float32_to_complex64_1d ( self ) : <EOL> x = np . asarray ( np . random . rand ( self . N ) , np . float32 ) <EOL> xf = np . fft . rfftn ( x ) <EOL> x_gpu = gpuarray . to_gpu ( x ) <EOL> xf_gpu = gpuarray . empty ( self . N // <NUM_LIT:2> + <NUM_LIT:1> , np . complex64 ) <EOL> plan = fft . Plan ( x . shape , np . float32 , np . complex64 ) <EOL> fft . fft ( x_gpu , xf_gpu , plan ) <EOL> assert np . allclose ( xf , xf_gpu . get ( ) , atol = atol_float32 ) <EOL> def test_fft_float32_to_complex64_2d ( self ) : <EOL> x = np . asarray ( np . random . rand ( self . N , self . M ) , np . float32 ) <EOL> xf = np . fft . rfftn ( x ) <EOL> x_gpu = gpuarray . to_gpu ( x ) <EOL> xf_gpu = gpuarray . empty ( ( self . N , self . M // <NUM_LIT:2> + <NUM_LIT:1> ) , np . complex64 ) <EOL> plan = fft . Plan ( x . shape , np . float32 , np . complex64 ) <EOL> fft . fft ( x_gpu , xf_gpu , plan ) <EOL> assert np . allclose ( xf , xf_gpu . get ( ) , atol = atol_float32 ) <EOL> def test_batch_fft_float32_to_complex64_1d ( self ) : <EOL> x = np . asarray ( np . random . rand ( self . B , self . N ) , np . float32 ) <EOL> xf = np . fft . rfft ( x , axis = <NUM_LIT:1> ) <EOL> x_gpu = gpuarray . to_gpu ( x ) <EOL> xf_gpu = gpuarray . empty ( ( self . B , self . N // <NUM_LIT:2> + <NUM_LIT:1> ) , np . complex64 ) <EOL> plan = fft . Plan ( x . shape [ <NUM_LIT:1> ] , np . float32 , np . complex64 , batch = self . B ) <EOL> fft . fft ( x_gpu , xf_gpu , plan ) <EOL> assert np . allclose ( xf , xf_gpu . get ( ) , atol = atol_float32 ) <EOL> def test_batch_fft_float32_to_complex64_2d ( self ) : <EOL> x = np . asarray ( np . random . rand ( self . B , self . N , self . M ) , np . float32 ) <EOL> xf = np . fft . rfftn ( x , axes = ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> x_gpu = gpuarray . to_gpu ( x ) <EOL> xf_gpu = gpuarray . empty ( ( self . B , self . N , self . M // <NUM_LIT:2> + <NUM_LIT:1> ) , np . complex64 ) <EOL> plan = fft . Plan ( [ self . N , self . M ] , np . float32 , np . complex64 , batch = self . B ) <EOL> fft . fft ( x_gpu , xf_gpu , plan ) <EOL> assert np . allclose ( xf , xf_gpu . get ( ) , atol = atol_float32 ) <EOL> def test_fft_float64_to_complex128_1d ( self ) : <EOL> x = np . asarray ( np . random . rand ( self . N ) , np . float64 ) <EOL> xf = np . fft . rfftn ( x ) <EOL> x_gpu = gpuarray . to_gpu ( x ) <EOL> xf_gpu = gpuarray . empty ( self . N // <NUM_LIT:2> + <NUM_LIT:1> , np . complex128 ) <EOL> plan = fft . Plan ( x . shape , np . float64 , np . complex128 ) <EOL> fft . fft ( x_gpu , xf_gpu , plan ) <EOL> assert np . allclose ( xf , xf_gpu . get ( ) , atol = atol_float64 ) <EOL> def test_fft_float64_to_complex128_2d ( self ) : <EOL> x = np . asarray ( np . random . rand ( self . N , self . M ) , np . float64 ) <EOL> xf = np . fft . rfftn ( x ) <EOL> x_gpu = gpuarray . to_gpu ( x ) <EOL> xf_gpu = gpuarray . empty ( ( self . N , self . M // <NUM_LIT:2> + <NUM_LIT:1> ) , np . complex128 ) <EOL> plan = fft . Plan ( x . shape , np . float64 , np . complex128 ) <EOL> fft . fft ( x_gpu , xf_gpu , plan ) <EOL> assert np . allclose ( xf , xf_gpu . get ( ) , atol = atol_float64 ) <EOL> def test_batch_fft_float64_to_complex128_1d ( self ) : <EOL> x = np . asarray ( np . random . rand ( self . B , self . N ) , np . float64 ) <EOL> xf = np . fft . rfft ( x , axis = <NUM_LIT:1> ) <EOL> x_gpu = gpuarray . to_gpu ( x ) <EOL> xf_gpu = gpuarray . empty ( ( self . B , self . N // <NUM_LIT:2> + <NUM_LIT:1> ) , np . complex128 ) <EOL> plan = fft . Plan ( x . shape [ <NUM_LIT:1> ] , np . float64 , np . complex128 , batch = self . B ) <EOL> fft . fft ( x_gpu , xf_gpu , plan ) <EOL> assert np . allclose ( xf , xf_gpu . get ( ) , atol = atol_float64 ) <EOL> def test_batch_fft_float64_to_complex128_2d ( self ) : <EOL> x = np . asarray ( np . random . rand ( self . B , self . N , self . M ) , np . float64 ) <EOL> xf = np . fft . rfftn ( x , axes = ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> x_gpu = gpuarray . to_gpu ( x ) <EOL> xf_gpu = gpuarray . empty ( ( self . B , self . N , self . M // <NUM_LIT:2> + <NUM_LIT:1> ) , np . complex128 ) <EOL> plan = fft . Plan ( [ self . N , self . M ] , np . float64 , np . complex128 , batch = self . B ) <EOL> fft . fft ( x_gpu , xf_gpu , plan ) <EOL> assert np . allclose ( xf , xf_gpu . get ( ) , atol = atol_float64 ) <EOL> def test_ifft_complex64_to_float32_1d ( self ) : <EOL> x = np . asarray ( np . random . rand ( self . N ) , np . float32 ) <EOL> xf = np . asarray ( np . fft . rfftn ( x ) , np . complex64 ) <EOL> xf_gpu = gpuarray . to_gpu ( xf ) <EOL> x_gpu = gpuarray . empty ( self . N , np . float32 ) <EOL> plan = fft . Plan ( x . shape , np . complex64 , np . float32 ) <EOL> fft . ifft ( xf_gpu , x_gpu , plan , True ) <EOL> assert np . allclose ( x , x_gpu . get ( ) , atol = atol_float32 ) <EOL> def test_ifft_complex64_to_float32_2d ( self ) : <EOL> x = np . asarray ( np . random . rand ( self . N , self . M ) , np . float32 ) <EOL> xf = np . asarray ( np . fft . rfftn ( x ) , np . complex64 ) <EOL> xf_gpu = gpuarray . to_gpu ( np . ascontiguousarray ( xf ) ) <EOL> x_gpu = gpuarray . empty ( ( self . N , self . M ) , np . float32 ) <EOL> plan = fft . Plan ( x . shape , np . complex64 , np . float32 ) <EOL> fft . ifft ( xf_gpu , x_gpu , plan , True ) <EOL> assert np . allclose ( x , x_gpu . get ( ) , atol = atol_float32 ) <EOL> def test_batch_ifft_complex64_to_float32_1d ( self ) : <EOL> x = np . asarray ( np . random . rand ( self . B , self . N ) , np . float32 ) <EOL> xf = np . asarray ( np . fft . rfft ( x , axis = <NUM_LIT:1> ) , np . complex64 ) <EOL> xf_gpu = gpuarray . to_gpu ( np . ascontiguousarray ( xf ) ) <EOL> x_gpu = gpuarray . empty ( ( self . B , self . N ) , np . float32 ) <EOL> plan = fft . Plan ( x . shape [ <NUM_LIT:1> ] , np . complex64 , np . float32 , batch = self . B ) <EOL> fft . ifft ( xf_gpu , x_gpu , plan , True ) <EOL> assert np . allclose ( x , x_gpu . get ( ) , atol = atol_float32 ) <EOL> def test_batch_ifft_complex64_to_float32_2d ( self ) : <EOL> x = np . asarray ( np . random . rand ( self . B , self . N , self . M ) , np . float32 ) <EOL> xf = np . asarray ( np . fft . rfftn ( x , axes = ( <NUM_LIT:1> , <NUM_LIT:2> ) ) , np . complex64 ) <EOL> xf_gpu = gpuarray . to_gpu ( np . ascontiguousarray ( xf ) ) <EOL> x_gpu = gpuarray . empty ( ( self . B , self . N , self . M ) , np . float32 ) <EOL> plan = fft . Plan ( [ self . N , self . M ] , np . complex64 , np . float32 , batch = self . B ) <EOL> fft . ifft ( xf_gpu , x_gpu , plan , True ) <EOL> assert np . allclose ( x , x_gpu . get ( ) , atol = atol_float32 ) <EOL> def test_ifft_complex128_to_float64_1d ( self ) : <EOL> x = np . asarray ( np . random . rand ( self . N ) , np . float64 ) <EOL> xf = np . asarray ( np . fft . rfftn ( x ) , np . complex128 ) <EOL> xf_gpu = gpuarray . to_gpu ( xf ) <EOL> x_gpu = gpuarray . empty ( self . N , np . float64 ) <EOL> plan = fft . Plan ( x . shape , np . complex128 , np . float64 ) <EOL> fft . ifft ( xf_gpu , x_gpu , plan , True ) <EOL> assert np . allclose ( x , x_gpu . get ( ) , atol = atol_float64 ) <EOL> def test_ifft_complex128_to_float64_2d ( self ) : <EOL> x = np . asarray ( np . random . rand ( self . N , self . M ) , np . float64 ) <EOL> xf = np . asarray ( np . fft . rfftn ( x ) , np . complex128 ) <EOL> xf_gpu = gpuarray . to_gpu ( np . ascontiguousarray ( xf ) ) <EOL> x_gpu = gpuarray . empty ( ( self . N , self . M ) , np . float64 ) <EOL> plan = fft . Plan ( x . shape , np . complex128 , np . float64 ) <EOL> fft . ifft ( xf_gpu , x_gpu , plan , True ) <EOL> assert np . allclose ( x , x_gpu . get ( ) , atol = atol_float64 ) <EOL> def test_batch_ifft_complex128_to_float64_1d ( self ) : <EOL> x = np . asarray ( np . random . rand ( self . B , self . N ) , np . float64 ) <EOL> xf = np . asarray ( np . fft . rfft ( x , axis = <NUM_LIT:1> ) , np . complex128 ) <EOL> xf_gpu = gpuarray . to_gpu ( np . ascontiguousarray ( xf ) ) <EOL> x_gpu = gpuarray . empty ( ( self . B , self . N ) , np . float64 ) <EOL> plan = fft . Plan ( x . shape [ <NUM_LIT:1> ] , np . complex128 , np . float64 , batch = self . B ) <EOL> fft . ifft ( xf_gpu , x_gpu , plan , True ) <EOL> assert np . allclose ( x , x_gpu . get ( ) , atol = atol_float64 ) <EOL> def test_batch_ifft_complex128_to_float64_2d ( self ) : <EOL> x = np . asarray ( np . random . rand ( self . B , self . N , self . M ) , np . float64 ) <EOL> xf = np . asarray ( np . fft . rfftn ( x , axes = ( <NUM_LIT:1> , <NUM_LIT:2> ) ) , np . complex128 ) <EOL> xf_gpu = gpuarray . to_gpu ( np . ascontiguousarray ( xf ) ) <EOL> x_gpu = gpuarray . empty ( ( self . B , self . N , self . M ) , np . float64 ) <EOL> plan = fft . Plan ( [ self . N , self . M ] , np . complex128 , np . float64 , batch = self . B ) <EOL> fft . ifft ( xf_gpu , x_gpu , plan , True ) <EOL> assert np . allclose ( x , x_gpu . get ( ) , atol = atol_float64 ) <EOL> def test_multiple_streams ( self ) : <EOL> x = np . asarray ( np . random . rand ( self . N ) , np . float32 ) <EOL> xf = np . fft . rfftn ( x ) <EOL> y = np . asarray ( np . random . rand ( self . N ) , np . float32 ) <EOL> yf = np . fft . rfftn ( y ) <EOL> x_gpu = gpuarray . to_gpu ( x ) <EOL> y_gpu = gpuarray . to_gpu ( y ) <EOL> xf_gpu = gpuarray . empty ( self . N // <NUM_LIT:2> + <NUM_LIT:1> , np . complex64 ) <EOL> yf_gpu = gpuarray . empty ( self . N // <NUM_LIT:2> + <NUM_LIT:1> , np . complex64 ) <EOL> stream0 = drv . Stream ( ) <EOL> stream1 = drv . Stream ( ) <EOL> plan1 = fft . Plan ( x . shape , np . float32 , np . complex64 , stream = stream0 ) <EOL> plan2 = fft . Plan ( y . shape , np . float32 , np . complex64 , stream = stream1 ) <EOL> fft . fft ( x_gpu , xf_gpu , plan1 ) <EOL> fft . fft ( y_gpu , yf_gpu , plan2 ) <EOL> assert np . allclose ( xf , xf_gpu . get ( ) , atol = atol_float32 ) <EOL> assert np . allclose ( yf , yf_gpu . get ( ) , atol = atol_float32 ) <EOL> def test_work_area ( self ) : <EOL> x = np . asarray ( np . random . rand ( self . N ) , np . float32 ) <EOL> xf = np . fft . rfftn ( x ) <EOL> x_gpu = gpuarray . to_gpu ( x ) <EOL> xf_gpu = gpuarray . empty ( self . N // <NUM_LIT:2> + <NUM_LIT:1> , np . complex64 ) <EOL> plan = fft . Plan ( x . shape , np . float32 , np . complex64 , auto_allocate = False ) <EOL> work_area = gpuarray . empty ( ( plan . worksize , ) , np . uint8 ) <EOL> plan . set_work_area ( work_area ) <EOL> fft . fft ( x_gpu , xf_gpu , plan ) <EOL> assert np . allclose ( xf , xf_gpu . get ( ) , atol = atol_float32 ) <EOL> def suite ( ) : <EOL> s = TestSuite ( ) <EOL> s . addTest ( test_fft ( '<STR_LIT>' ) ) <EOL> s . addTest ( test_fft ( '<STR_LIT>' ) ) <EOL> s . addTest ( test_fft ( '<STR_LIT>' ) ) <EOL> s . addTest ( test_fft ( '<STR_LIT>' ) ) <EOL> s . addTest ( test_fft ( '<STR_LIT>' ) ) <EOL> s . addTest ( test_fft ( '<STR_LIT>' ) ) <EOL> s . addTest ( test_fft ( '<STR_LIT>' ) ) <EOL> s . addTest ( test_fft ( '<STR_LIT>' ) ) <EOL> s . addTest ( test_fft ( '<STR_LIT>' ) ) <EOL> s . addTest ( test_fft ( '<STR_LIT>' ) ) <EOL> if misc . get_compute_capability ( pycuda . autoinit . device ) >= <NUM_LIT> : <EOL> s . addTest ( test_fft ( '<STR_LIT>' ) ) <EOL> s . addTest ( test_fft ( '<STR_LIT>' ) ) <EOL> s . addTest ( test_fft ( '<STR_LIT>' ) ) <EOL> s . addTest ( test_fft ( '<STR_LIT>' ) ) <EOL> s . addTest ( test_fft ( '<STR_LIT>' ) ) <EOL> s . addTest ( test_fft ( '<STR_LIT>' ) ) <EOL> s . addTest ( test_fft ( '<STR_LIT>' ) ) <EOL> s . addTest ( test_fft ( '<STR_LIT>' ) ) <EOL> return s <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( defaultTest = '<STR_LIT>' ) </s>
