<s> from __future__ import print_function , absolute_import , division <EOL> import cmath <EOL> import itertools <EOL> import math <EOL> import sys <EOL> from numba import unittest_support as unittest <EOL> from numba . compiler import compile_isolated , Flags , utils <EOL> from numba import types <EOL> from . support import TestCase , tag <EOL> from . complex_usecases import * <EOL> enable_pyobj_flags = Flags ( ) <EOL> enable_pyobj_flags . set ( "<STR_LIT>" ) <EOL> no_pyobj_flags = Flags ( ) <EOL> class BaseComplexTest ( object ) : <EOL> def basic_values ( self ) : <EOL> reals = [ - <NUM_LIT:0.0> , + <NUM_LIT:0.0> , <NUM_LIT:1> , - <NUM_LIT:1> , + <NUM_LIT> , - <NUM_LIT> , <EOL> float ( '<STR_LIT>' ) , float ( '<STR_LIT>' ) ] <EOL> if sys . platform != '<STR_LIT:win32>' : <EOL> reals += [ float ( '<STR_LIT>' ) ] <EOL> return [ complex ( x , y ) for x , y in itertools . product ( reals , reals ) ] <EOL> def more_values ( self ) : <EOL> reals = [ - <NUM_LIT:0.0> , + <NUM_LIT:0.0> , <NUM_LIT:1> , - <NUM_LIT:1> , - math . pi , + math . pi , <EOL> float ( '<STR_LIT>' ) , float ( '<STR_LIT>' ) ] <EOL> if sys . platform != '<STR_LIT:win32>' : <EOL> reals += [ float ( '<STR_LIT>' ) ] <EOL> return [ complex ( x , y ) for x , y in itertools . product ( reals , reals ) ] <EOL> def non_nan_values ( self ) : <EOL> reals = [ - <NUM_LIT:0.0> , + <NUM_LIT:0.0> , <NUM_LIT:1> , - <NUM_LIT:1> , - math . pi , + math . pi , <EOL> float ( '<STR_LIT>' ) , float ( '<STR_LIT>' ) ] <EOL> return [ complex ( x , y ) for x , y in itertools . product ( reals , reals ) ] <EOL> def run_unary ( self , pyfunc , x_types , x_values , ulps = <NUM_LIT:1> , <EOL> flags = enable_pyobj_flags ) : <EOL> for tx in x_types : <EOL> cr = compile_isolated ( pyfunc , [ tx ] , flags = flags ) <EOL> cfunc = cr . entry_point <EOL> prec = '<STR_LIT>' if tx in ( types . float32 , types . complex64 ) else '<STR_LIT>' <EOL> for vx in x_values : <EOL> try : <EOL> expected = pyfunc ( vx ) <EOL> except ValueError as e : <EOL> self . assertIn ( "<STR_LIT>" , str ( e ) ) <EOL> continue <EOL> got = cfunc ( vx ) <EOL> msg = '<STR_LIT>' % ( vx , prec ) <EOL> self . assertPreciseEqual ( got , expected , prec = prec , <EOL> ulps = ulps , msg = msg ) <EOL> def run_binary ( self , pyfunc , value_types , values , ulps = <NUM_LIT:1> , <EOL> flags = enable_pyobj_flags ) : <EOL> for tx , ty in value_types : <EOL> cr = compile_isolated ( pyfunc , [ tx , ty ] , flags = flags ) <EOL> cfunc = cr . entry_point <EOL> prec = ( '<STR_LIT>' <EOL> if set ( [ tx , ty ] ) & set ( [ types . float32 , types . complex64 ] ) <EOL> else '<STR_LIT>' ) <EOL> for vx , vy in values : <EOL> try : <EOL> expected = pyfunc ( vx , vy ) <EOL> except ValueError as e : <EOL> self . assertIn ( "<STR_LIT>" , str ( e ) ) <EOL> continue <EOL> except ZeroDivisionError : <EOL> continue <EOL> got = cfunc ( vx , vy ) <EOL> msg = '<STR_LIT>' % ( ( vx , vy ) , prec ) <EOL> self . assertPreciseEqual ( got , expected , prec = prec , <EOL> ulps = ulps , msg = msg ) <EOL> class TestComplex ( BaseComplexTest , TestCase ) : <EOL> def test_real ( self , flags = enable_pyobj_flags ) : <EOL> self . run_unary ( real_usecase , [ types . complex64 , types . complex128 ] , <EOL> self . basic_values ( ) , flags = flags ) <EOL> self . run_unary ( real_usecase , [ types . int8 , types . int64 ] , <EOL> [ <NUM_LIT:1> , <NUM_LIT:0> , - <NUM_LIT:3> ] , flags = flags ) <EOL> self . run_unary ( real_usecase , [ types . float32 , types . float64 ] , <EOL> [ <NUM_LIT> , - <NUM_LIT:0.5> ] , flags = flags ) <EOL> def test_real_npm ( self ) : <EOL> self . test_real ( flags = no_pyobj_flags ) <EOL> def test_imag ( self , flags = enable_pyobj_flags ) : <EOL> self . run_unary ( imag_usecase , [ types . complex64 , types . complex128 ] , <EOL> self . basic_values ( ) , flags = flags ) <EOL> self . run_unary ( imag_usecase , [ types . int8 , types . int64 ] , <EOL> [ <NUM_LIT:1> , <NUM_LIT:0> , - <NUM_LIT:3> ] , flags = flags ) <EOL> self . run_unary ( imag_usecase , [ types . float32 , types . float64 ] , <EOL> [ <NUM_LIT> , - <NUM_LIT:0.5> ] , flags = flags ) <EOL> def test_imag_npm ( self ) : <EOL> self . test_imag ( flags = no_pyobj_flags ) <EOL> def test_conjugate ( self , flags = enable_pyobj_flags ) : <EOL> self . run_unary ( conjugate_usecase , [ types . complex64 , types . complex128 ] , <EOL> self . basic_values ( ) , flags = flags ) <EOL> self . run_unary ( conjugate_usecase , [ types . int8 , types . int64 ] , <EOL> [ <NUM_LIT:1> , <NUM_LIT:0> , - <NUM_LIT:3> ] , flags = flags ) <EOL> self . run_unary ( conjugate_usecase , [ types . float32 , types . float64 ] , <EOL> [ <NUM_LIT> , - <NUM_LIT:0.5> ] , flags = flags ) <EOL> def test_conjugate_npm ( self ) : <EOL> self . test_conjugate ( flags = no_pyobj_flags ) <EOL> def test_div ( self , flags = enable_pyobj_flags ) : <EOL> """<STR_LIT>""" <EOL> values = list ( itertools . product ( self . more_values ( ) , self . more_values ( ) ) ) <EOL> value_types = [ ( types . complex128 , types . complex128 ) , <EOL> ( types . complex64 , types . complex64 ) ] <EOL> self . run_binary ( div_usecase , value_types , values , flags = flags ) <EOL> @ tag ( '<STR_LIT>' ) <EOL> def test_div_npm ( self ) : <EOL> self . test_div ( flags = no_pyobj_flags ) <EOL> class TestCMath ( BaseComplexTest , TestCase ) : <EOL> """<STR_LIT>""" <EOL> def check_predicate_func ( self , pyfunc , flags ) : <EOL> self . run_unary ( pyfunc , [ types . complex128 , types . complex64 ] , <EOL> self . basic_values ( ) , flags = flags ) <EOL> def check_unary_func ( self , pyfunc , flags , ulps = <NUM_LIT:1> , values = None ) : <EOL> self . run_unary ( pyfunc , [ types . complex128 ] , <EOL> values or self . more_values ( ) , flags = flags , ulps = ulps ) <EOL> self . run_unary ( pyfunc , [ types . complex64 ] , <EOL> values or self . basic_values ( ) , flags = flags , ulps = ulps ) <EOL> def test_phase ( self ) : <EOL> self . check_unary_func ( phase_usecase , enable_pyobj_flags ) <EOL> def test_phase_npm ( self ) : <EOL> self . check_unary_func ( phase_usecase , no_pyobj_flags ) <EOL> def test_polar ( self ) : <EOL> self . check_unary_func ( polar_usecase , enable_pyobj_flags ) <EOL> def test_polar_npm ( self ) : <EOL> self . check_unary_func ( polar_usecase , no_pyobj_flags ) <EOL> def test_rect ( self , flags = enable_pyobj_flags ) : <EOL> def do_test ( tp , seed_values ) : <EOL> values = [ ( z . real , z . imag ) for z in seed_values <EOL> if not math . isinf ( z . imag ) or z . real == <NUM_LIT:0> ] <EOL> self . run_binary ( rect_usecase , [ ( tp , tp ) ] , values , flags = flags ) <EOL> do_test ( types . float64 , self . more_values ( ) ) <EOL> do_test ( types . float32 , self . basic_values ( ) ) <EOL> def test_rect_npm ( self ) : <EOL> self . test_rect ( flags = no_pyobj_flags ) <EOL> def test_isnan ( self , flags = enable_pyobj_flags ) : <EOL> self . check_predicate_func ( isnan_usecase , enable_pyobj_flags ) <EOL> @ tag ( '<STR_LIT>' ) <EOL> def test_isnan_npm ( self ) : <EOL> self . check_predicate_func ( isnan_usecase , no_pyobj_flags ) <EOL> def test_isinf ( self , flags = enable_pyobj_flags ) : <EOL> self . check_predicate_func ( isinf_usecase , enable_pyobj_flags ) <EOL> @ tag ( '<STR_LIT>' ) <EOL> def test_isinf_npm ( self ) : <EOL> self . check_predicate_func ( isinf_usecase , no_pyobj_flags ) <EOL> @ unittest . skipIf ( utils . PYVERSION < ( <NUM_LIT:3> , <NUM_LIT:2> ) , "<STR_LIT>" ) <EOL> def test_isfinite ( self , flags = enable_pyobj_flags ) : <EOL> self . check_predicate_func ( isfinite_usecase , enable_pyobj_flags ) <EOL> @ unittest . skipIf ( utils . PYVERSION < ( <NUM_LIT:3> , <NUM_LIT:2> ) , "<STR_LIT>" ) <EOL> def test_isfinite_npm ( self ) : <EOL> self . check_predicate_func ( isfinite_usecase , no_pyobj_flags ) <EOL> def test_exp ( self ) : <EOL> self . check_unary_func ( exp_usecase , enable_pyobj_flags , ulps = <NUM_LIT:2> ) <EOL> def test_exp_npm ( self ) : <EOL> self . check_unary_func ( exp_usecase , no_pyobj_flags , ulps = <NUM_LIT:2> ) <EOL> def test_log ( self ) : <EOL> self . check_unary_func ( log_usecase , enable_pyobj_flags ) <EOL> def test_log_npm ( self ) : <EOL> self . check_unary_func ( log_usecase , no_pyobj_flags ) <EOL> def test_log_base ( self , flags = enable_pyobj_flags ) : <EOL> values = list ( itertools . product ( self . more_values ( ) , self . more_values ( ) ) ) <EOL> value_types = [ ( types . complex128 , types . complex128 ) , <EOL> ( types . complex64 , types . complex64 ) ] <EOL> self . run_binary ( log_base_usecase , value_types , values , flags = flags , <EOL> ulps = <NUM_LIT:3> ) <EOL> def test_log_base_npm ( self ) : <EOL> self . test_log_base ( flags = no_pyobj_flags ) <EOL> def test_log10 ( self ) : <EOL> self . check_unary_func ( log10_usecase , enable_pyobj_flags ) <EOL> def test_log10_npm ( self ) : <EOL> self . check_unary_func ( log10_usecase , no_pyobj_flags ) <EOL> def test_sqrt ( self ) : <EOL> self . check_unary_func ( sqrt_usecase , enable_pyobj_flags ) <EOL> def test_sqrt_npm ( self ) : <EOL> self . check_unary_func ( sqrt_usecase , no_pyobj_flags ) <EOL> def test_acos ( self ) : <EOL> self . check_unary_func ( acos_usecase , enable_pyobj_flags , ulps = <NUM_LIT:2> ) <EOL> def test_acos_npm ( self ) : <EOL> self . check_unary_func ( acos_usecase , no_pyobj_flags , ulps = <NUM_LIT:2> ) <EOL> def test_asin ( self ) : <EOL> self . check_unary_func ( asin_usecase , enable_pyobj_flags , ulps = <NUM_LIT:2> ) <EOL> def test_asin_npm ( self ) : <EOL> self . check_unary_func ( asin_usecase , no_pyobj_flags , ulps = <NUM_LIT:2> ) <EOL> def test_atan ( self ) : <EOL> self . check_unary_func ( atan_usecase , enable_pyobj_flags , ulps = <NUM_LIT:2> , ) <EOL> def test_atan_npm ( self ) : <EOL> self . check_unary_func ( atan_usecase , no_pyobj_flags , ulps = <NUM_LIT:2> , ) <EOL> def test_cos ( self ) : <EOL> self . check_unary_func ( cos_usecase , enable_pyobj_flags , ulps = <NUM_LIT:2> ) <EOL> def test_cos_npm ( self ) : <EOL> self . check_unary_func ( cos_usecase , no_pyobj_flags , ulps = <NUM_LIT:2> ) <EOL> def test_sin ( self ) : <EOL> self . check_unary_func ( sin_usecase , enable_pyobj_flags ) <EOL> def test_sin_npm ( self ) : <EOL> self . check_unary_func ( sin_usecase , no_pyobj_flags ) <EOL> def test_tan ( self ) : <EOL> self . check_unary_func ( tan_usecase , enable_pyobj_flags , ulps = <NUM_LIT:2> ) <EOL> def test_tan_npm ( self ) : <EOL> self . check_unary_func ( tan_usecase , enable_pyobj_flags , ulps = <NUM_LIT:2> ) <EOL> def test_acosh ( self ) : <EOL> self . check_unary_func ( acosh_usecase , enable_pyobj_flags ) <EOL> def test_acosh_npm ( self ) : <EOL> self . check_unary_func ( acosh_usecase , no_pyobj_flags ) <EOL> def test_asinh ( self ) : <EOL> self . check_unary_func ( asinh_usecase , enable_pyobj_flags , ulps = <NUM_LIT:2> ) <EOL> def test_asinh_npm ( self ) : <EOL> self . check_unary_func ( asinh_usecase , no_pyobj_flags , ulps = <NUM_LIT:2> ) <EOL> def test_atanh ( self ) : <EOL> self . check_unary_func ( atanh_usecase , enable_pyobj_flags , ulps = <NUM_LIT:2> ) <EOL> def test_atanh_npm ( self ) : <EOL> self . check_unary_func ( atanh_usecase , no_pyobj_flags , ulps = <NUM_LIT:2> ) <EOL> def test_cosh ( self ) : <EOL> self . check_unary_func ( cosh_usecase , enable_pyobj_flags , ulps = <NUM_LIT:2> ) <EOL> def test_cosh_npm ( self ) : <EOL> self . check_unary_func ( cosh_usecase , no_pyobj_flags , ulps = <NUM_LIT:2> ) <EOL> def test_sinh ( self ) : <EOL> self . check_unary_func ( sinh_usecase , enable_pyobj_flags ) <EOL> def test_sinh_npm ( self ) : <EOL> self . check_unary_func ( sinh_usecase , no_pyobj_flags ) <EOL> def test_tanh ( self ) : <EOL> self . check_unary_func ( tanh_usecase , enable_pyobj_flags , ulps = <NUM_LIT:2> ) <EOL> def test_tanh_npm ( self ) : <EOL> self . check_unary_func ( tanh_usecase , enable_pyobj_flags , ulps = <NUM_LIT:2> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
