<s> """<STR_LIT>""" <EOL> from __future__ import division , print_function , absolute_import <EOL> import sys <EOL> from platform import python_compiler , machine <EOL> from distutils . version import LooseVersion <EOL> import itertools <EOL> import numpy as np <EOL> from . . externals . six import BytesIO <EOL> from . . arraywriters import ( SlopeInterArrayWriter , SlopeArrayWriter , <EOL> WriterError , ScalingError , ArrayWriter , <EOL> make_array_writer , get_slope_inter ) <EOL> from . . casting import int_abs , type_info , shared_range , on_powerpc <EOL> from . . volumeutils import array_from_file , apply_read_scaling , _dt_min_max <EOL> from numpy . testing import ( assert_array_almost_equal , <EOL> assert_array_equal ) <EOL> from nose . tools import ( assert_true , assert_false , <EOL> assert_equal , assert_not_equal , <EOL> assert_raises ) <EOL> from . . testing import ( assert_allclose_safely , suppress_warnings , <EOL> error_warnings ) <EOL> FLOAT_TYPES = np . sctypes [ '<STR_LIT:float>' ] <EOL> COMPLEX_TYPES = np . sctypes [ '<STR_LIT>' ] <EOL> INT_TYPES = np . sctypes [ '<STR_LIT:int>' ] <EOL> UINT_TYPES = np . sctypes [ '<STR_LIT>' ] <EOL> CFLOAT_TYPES = FLOAT_TYPES + COMPLEX_TYPES <EOL> IUINT_TYPES = INT_TYPES + UINT_TYPES <EOL> NUMERIC_TYPES = CFLOAT_TYPES + IUINT_TYPES <EOL> NP_VERSION = LooseVersion ( np . __version__ ) <EOL> def round_trip ( writer , order = '<STR_LIT:F>' , apply_scale = True ) : <EOL> sio = BytesIO ( ) <EOL> arr = writer . array <EOL> with np . errstate ( invalid = '<STR_LIT:ignore>' ) : <EOL> writer . to_fileobj ( sio , order ) <EOL> data_back = array_from_file ( arr . shape , writer . out_dtype , sio , order = order ) <EOL> slope , inter = get_slope_inter ( writer ) <EOL> if apply_scale : <EOL> data_back = apply_read_scaling ( data_back , slope , inter ) <EOL> return data_back <EOL> def test_arraywriters ( ) : <EOL> if machine ( ) == '<STR_LIT>' and python_compiler ( ) . startswith ( '<STR_LIT>' ) : <EOL> test_types = FLOAT_TYPES + IUINT_TYPES <EOL> else : <EOL> test_types = NUMERIC_TYPES <EOL> for klass in ( SlopeInterArrayWriter , SlopeArrayWriter , ArrayWriter ) : <EOL> for type in test_types : <EOL> arr = np . arange ( <NUM_LIT:10> , dtype = type ) <EOL> aw = klass ( arr ) <EOL> assert_true ( aw . array is arr ) <EOL> assert_equal ( aw . out_dtype , arr . dtype ) <EOL> assert_array_equal ( arr , round_trip ( aw ) ) <EOL> bs_arr = arr . byteswap ( ) . newbyteorder ( '<STR_LIT:S>' ) <EOL> if not np . all ( bs_arr == arr ) : <EOL> assert_true ( NP_VERSION <= LooseVersion ( '<STR_LIT>' ) ) <EOL> assert_true ( on_powerpc ( ) ) <EOL> assert_true ( type == np . complex256 ) <EOL> else : <EOL> bs_aw = klass ( bs_arr ) <EOL> bs_aw_rt = round_trip ( bs_aw ) <EOL> if NP_VERSION == '<STR_LIT>' and sys . version_info [ : <NUM_LIT:2> ] == ( <NUM_LIT:3> , <NUM_LIT:3> ) : <EOL> assert_array_equal_ = lambda x , y : np . all ( [ x_ == y_ for x_ , y_ in zip ( x , y ) ] ) <EOL> else : <EOL> assert_array_equal_ = assert_array_equal <EOL> assert_array_equal_ ( arr , bs_aw_rt ) <EOL> bs_aw2 = klass ( bs_arr , arr . dtype ) <EOL> bs_aw2_rt = round_trip ( bs_aw2 ) <EOL> assert_array_equal ( arr , bs_aw2_rt ) <EOL> arr2 = np . reshape ( arr , ( <NUM_LIT:2> , <NUM_LIT:5> ) ) <EOL> a2w = klass ( arr2 ) <EOL> arr_back = round_trip ( a2w ) <EOL> assert_array_equal ( arr2 , arr_back ) <EOL> arr_back = round_trip ( a2w , '<STR_LIT:F>' ) <EOL> assert_array_equal ( arr2 , arr_back ) <EOL> arr_back = round_trip ( a2w , '<STR_LIT:C>' ) <EOL> assert_array_equal ( arr2 , arr_back ) <EOL> assert_true ( arr_back . flags . c_contiguous ) <EOL> def test_arraywriter_check_scaling ( ) : <EOL> arr = np . array ( [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:255> ] , np . uint8 ) <EOL> aw = ArrayWriter ( arr ) <EOL> assert_raises ( WriterError , ArrayWriter , arr , np . int8 ) <EOL> assert_raises ( WriterError , ArrayWriter , arr , np . int8 , check_scaling = True ) <EOL> aw = ArrayWriter ( arr , np . int8 , check_scaling = False ) <EOL> assert_array_equal ( round_trip ( aw ) , np . clip ( arr , <NUM_LIT:0> , <NUM_LIT> ) ) <EOL> assert_raises ( TypeError , ArrayWriter , arr , np . int8 , False ) <EOL> def test_no_scaling ( ) : <EOL> for in_dtype , out_dtype , awt in itertools . product ( <EOL> NUMERIC_TYPES , <EOL> NUMERIC_TYPES , <EOL> ( ArrayWriter , SlopeArrayWriter , SlopeInterArrayWriter ) ) : <EOL> mn_in , mx_in = _dt_min_max ( in_dtype ) <EOL> arr = np . array ( [ mn_in , <NUM_LIT:0> , <NUM_LIT:1> , mx_in ] , dtype = in_dtype ) <EOL> kwargs = ( dict ( check_scaling = False ) if awt == ArrayWriter <EOL> else dict ( calc_scale = False ) ) <EOL> aw = awt ( arr , out_dtype , ** kwargs ) <EOL> with suppress_warnings ( ) : <EOL> back_arr = round_trip ( aw ) <EOL> exp_back = arr . copy ( ) <EOL> if out_dtype in IUINT_TYPES : <EOL> if in_dtype in CFLOAT_TYPES : <EOL> with suppress_warnings ( ) : <EOL> exp_back = exp_back . astype ( float ) <EOL> with np . errstate ( invalid = '<STR_LIT:ignore>' ) : <EOL> exp_back = np . round ( exp_back ) <EOL> if hasattr ( aw , '<STR_LIT>' ) and in_dtype in FLOAT_TYPES : <EOL> exp_back = np . clip ( exp_back , <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> else : <EOL> exp_back = np . clip ( exp_back , <EOL> * shared_range ( float , out_dtype ) ) <EOL> else : <EOL> mn_out , mx_out = _dt_min_max ( out_dtype ) <EOL> if ( mn_in , mx_in ) != ( mn_out , mx_out ) : <EOL> exp_back = np . clip ( exp_back , <EOL> max ( mn_in , mn_out ) , <EOL> min ( mx_in , mx_out ) ) <EOL> elif in_dtype in COMPLEX_TYPES : <EOL> with suppress_warnings ( ) : <EOL> exp_back = exp_back . astype ( float ) <EOL> exp_back = exp_back . astype ( out_dtype ) <EOL> assert_allclose_safely ( back_arr , exp_back ) <EOL> def test_scaling_needed ( ) : <EOL> dt_def = [ ( '<STR_LIT:f>' , '<STR_LIT>' ) ] <EOL> arr = np . ones ( <NUM_LIT:10> , dt_def ) <EOL> for t in NUMERIC_TYPES : <EOL> assert_raises ( WriterError , ArrayWriter , arr , t ) <EOL> narr = np . ones ( <NUM_LIT:10> , t ) <EOL> assert_raises ( WriterError , ArrayWriter , narr , dt_def ) <EOL> assert_false ( ArrayWriter ( arr ) . scaling_needed ( ) ) <EOL> assert_false ( ArrayWriter ( arr , dt_def ) . scaling_needed ( ) ) <EOL> for in_t in NUMERIC_TYPES : <EOL> for out_t in NUMERIC_TYPES : <EOL> if np . can_cast ( in_t , out_t ) : <EOL> aw = ArrayWriter ( np . ones ( <NUM_LIT:10> , in_t ) , out_t ) <EOL> assert_false ( aw . scaling_needed ( ) ) <EOL> for in_t in NUMERIC_TYPES : <EOL> arr = np . ones ( <NUM_LIT:10> , in_t ) <EOL> for out_t in COMPLEX_TYPES : <EOL> assert_false ( ArrayWriter ( arr , out_t ) . scaling_needed ( ) ) <EOL> for in_t in COMPLEX_TYPES : <EOL> for out_t in FLOAT_TYPES + IUINT_TYPES : <EOL> arr = np . ones ( <NUM_LIT:10> , in_t ) <EOL> assert_raises ( WriterError , ArrayWriter , arr , out_t ) <EOL> for in_t in FLOAT_TYPES + IUINT_TYPES : <EOL> arr = np . ones ( <NUM_LIT:10> , in_t ) <EOL> for out_t in FLOAT_TYPES : <EOL> assert_false ( ArrayWriter ( arr , out_t ) . scaling_needed ( ) ) <EOL> for in_t in FLOAT_TYPES + IUINT_TYPES : <EOL> arr_0 = np . zeros ( <NUM_LIT:10> , in_t ) <EOL> arr_e = [ ] <EOL> for out_t in IUINT_TYPES : <EOL> assert_false ( ArrayWriter ( arr_0 , out_t ) . scaling_needed ( ) ) <EOL> assert_false ( ArrayWriter ( arr_e , out_t ) . scaling_needed ( ) ) <EOL> for in_t in FLOAT_TYPES : <EOL> arr_nan = np . zeros ( <NUM_LIT:10> , in_t ) + np . nan <EOL> arr_inf = np . zeros ( <NUM_LIT:10> , in_t ) + np . inf <EOL> arr_minf = np . zeros ( <NUM_LIT:10> , in_t ) - np . inf <EOL> arr_mix = np . array ( [ np . nan , np . inf , - np . inf ] , dtype = in_t ) <EOL> for out_t in IUINT_TYPES : <EOL> for arr in ( arr_nan , arr_inf , arr_minf , arr_mix ) : <EOL> assert_true ( <EOL> ArrayWriter ( arr , out_t , check_scaling = False ) . scaling_needed ( ) ) <EOL> assert_false ( SlopeArrayWriter ( arr , out_t ) . scaling_needed ( ) ) <EOL> assert_false ( SlopeInterArrayWriter ( arr , out_t ) . scaling_needed ( ) ) <EOL> for in_t in FLOAT_TYPES : <EOL> arr = np . ones ( <NUM_LIT:10> , in_t ) <EOL> for out_t in IUINT_TYPES : <EOL> assert_true ( SlopeArrayWriter ( arr , out_t ) . scaling_needed ( ) ) <EOL> for in_t in IUINT_TYPES : <EOL> in_info = np . iinfo ( in_t ) <EOL> in_min , in_max = in_info . min , in_info . max <EOL> for out_t in IUINT_TYPES : <EOL> out_info = np . iinfo ( out_t ) <EOL> out_min , out_max = out_info . min , out_info . max <EOL> if in_min >= out_min and in_max <= out_max : <EOL> arr = np . array ( [ in_min , in_max ] , in_t ) <EOL> assert_true ( np . can_cast ( arr . dtype , out_t ) ) <EOL> assert_false ( ArrayWriter ( arr , out_t ) . scaling_needed ( ) ) <EOL> continue <EOL> max_min = max ( in_min , out_min ) <EOL> min_max = min ( in_max , out_max ) <EOL> arr = np . array ( [ max_min , min_max ] , in_t ) <EOL> assert_false ( ArrayWriter ( arr , out_t ) . scaling_needed ( ) ) <EOL> assert_true ( SlopeInterArrayWriter ( arr + <NUM_LIT:1> , out_t ) . scaling_needed ( ) ) <EOL> if in_t in INT_TYPES : <EOL> assert_true ( SlopeInterArrayWriter ( arr - <NUM_LIT:1> , out_t ) . scaling_needed ( ) ) <EOL> def test_special_rt ( ) : <EOL> arr = np . array ( [ np . inf , np . nan , - np . inf ] ) <EOL> for in_dtt in FLOAT_TYPES : <EOL> for out_dtt in IUINT_TYPES : <EOL> in_arr = arr . astype ( in_dtt ) <EOL> assert_raises ( WriterError , ArrayWriter , in_arr , out_dtt ) <EOL> aw = ArrayWriter ( in_arr , out_dtt , check_scaling = False ) <EOL> mn , mx = shared_range ( float , out_dtt ) <EOL> assert_true ( np . allclose ( round_trip ( aw ) . astype ( float ) , <EOL> [ mx , <NUM_LIT:0> , mn ] ) ) <EOL> for klass in ( SlopeArrayWriter , SlopeInterArrayWriter ) : <EOL> aw = klass ( in_arr , out_dtt ) <EOL> assert_equal ( get_slope_inter ( aw ) , ( <NUM_LIT:1> , <NUM_LIT:0> ) ) <EOL> assert_array_equal ( round_trip ( aw ) , <NUM_LIT:0> ) <EOL> for in_dtt , out_dtt , awt in itertools . product ( <EOL> FLOAT_TYPES , <EOL> IUINT_TYPES , <EOL> ( ArrayWriter , SlopeArrayWriter , SlopeInterArrayWriter ) ) : <EOL> arr = np . zeros ( ( <NUM_LIT:3> , ) , dtype = in_dtt ) <EOL> aw = awt ( arr , out_dtt ) <EOL> assert_equal ( get_slope_inter ( aw ) , ( <NUM_LIT:1> , <NUM_LIT:0> ) ) <EOL> assert_array_equal ( round_trip ( aw ) , <NUM_LIT:0> ) <EOL> def test_high_int2uint ( ) : <EOL> arr = np . array ( [ <NUM_LIT:2> ** <NUM_LIT> ] , dtype = np . uint64 ) <EOL> out_type = np . int64 <EOL> aw = SlopeInterArrayWriter ( arr , out_type ) <EOL> assert_equal ( aw . inter , <NUM_LIT:2> ** <NUM_LIT> ) <EOL> def test_slope_inter_castable ( ) : <EOL> for in_dtt in FLOAT_TYPES + IUINT_TYPES : <EOL> for out_dtt in NUMERIC_TYPES : <EOL> for klass in ( ArrayWriter , SlopeArrayWriter , SlopeInterArrayWriter ) : <EOL> arr = np . zeros ( ( <NUM_LIT:5> , ) , dtype = in_dtt ) <EOL> aw = klass ( arr , out_dtt ) <EOL> arr = np . array ( [ np . inf , np . nan , - np . inf ] ) <EOL> for in_dtt in FLOAT_TYPES : <EOL> for out_dtt in IUINT_TYPES : <EOL> in_arr = arr . astype ( in_dtt ) <EOL> assert_raises ( WriterError , ArrayWriter , in_arr , out_dtt ) <EOL> aw = SlopeArrayWriter ( arr . astype ( in_dtt ) , out_dtt ) <EOL> aw = SlopeInterArrayWriter ( arr . astype ( in_dtt ) , out_dtt ) <EOL> for in_dtt , out_dtt , arr , slope_only , slope_inter , neither in ( <EOL> ( np . float32 , np . float32 , <NUM_LIT:1> , True , True , True ) , <EOL> ( np . float64 , np . float32 , <NUM_LIT:1> , True , True , True ) , <EOL> ( np . float32 , np . complex128 , <NUM_LIT:1> , True , True , True ) , <EOL> ( np . uint32 , np . complex128 , <NUM_LIT:1> , True , True , True ) , <EOL> ( np . int64 , np . float32 , <NUM_LIT:1> , True , True , True ) , <EOL> ( np . float32 , np . int16 , <NUM_LIT:1> , True , True , False ) , <EOL> ( np . complex128 , np . float32 , <NUM_LIT:1> , False , False , False ) , <EOL> ( np . complex128 , np . int16 , <NUM_LIT:1> , False , False , False ) , <EOL> ( np . uint8 , np . int16 , <NUM_LIT:1> , True , True , True ) , <EOL> ( np . uint16 , np . int16 , <NUM_LIT:1> , True , True , True ) , <EOL> ( np . uint16 , np . int16 , <NUM_LIT:2> ** <NUM_LIT:16> - <NUM_LIT:1> , True , True , False ) , <EOL> ( np . uint16 , np . int16 , ( <NUM_LIT:0> , <NUM_LIT:2> ** <NUM_LIT:16> - <NUM_LIT:1> ) , True , True , False ) , <EOL> ( np . uint16 , np . uint8 , <NUM_LIT:1> , True , True , True ) , <EOL> ( np . int16 , np . uint16 , <NUM_LIT:1> , True , True , True ) , <EOL> ( np . int16 , np . uint16 , - <NUM_LIT:1> , True , True , False ) , <EOL> ( np . int16 , np . uint16 , ( - <NUM_LIT:1> , <NUM_LIT:1> ) , False , True , False ) , <EOL> ( np . int8 , np . uint16 , <NUM_LIT:1> , True , True , True ) , <EOL> ( np . int8 , np . uint16 , - <NUM_LIT:1> , True , True , False ) , <EOL> ( np . int8 , np . uint16 , ( - <NUM_LIT:1> , <NUM_LIT:1> ) , False , True , False ) , <EOL> ) : <EOL> data = np . array ( arr , dtype = in_dtt ) <EOL> if slope_only : <EOL> SlopeArrayWriter ( data , out_dtt ) <EOL> else : <EOL> assert_raises ( WriterError , SlopeArrayWriter , data , out_dtt ) <EOL> if slope_inter : <EOL> SlopeInterArrayWriter ( data , out_dtt ) <EOL> else : <EOL> assert_raises ( WriterError , SlopeInterArrayWriter , data , out_dtt ) <EOL> if neither : <EOL> ArrayWriter ( data , out_dtt ) <EOL> else : <EOL> assert_raises ( WriterError , ArrayWriter , data , out_dtt ) <EOL> def test_calculate_scale ( ) : <EOL> npa = np . array <EOL> SIAW = SlopeInterArrayWriter <EOL> SAW = SlopeArrayWriter <EOL> aw = SIAW ( npa ( [ - <NUM_LIT:2> , - <NUM_LIT:1> ] , dtype = np . int8 ) , np . uint8 ) <EOL> assert_equal ( get_slope_inter ( aw ) , ( <NUM_LIT:1.0> , - <NUM_LIT> ) ) <EOL> aw = SAW ( npa ( [ - <NUM_LIT:2> , - <NUM_LIT:1> ] , dtype = np . int8 ) , np . uint8 ) <EOL> assert_equal ( get_slope_inter ( aw ) , ( - <NUM_LIT:1.0> , <NUM_LIT:0.0> ) ) <EOL> aw = SAW ( npa ( [ - <NUM_LIT:2> , <NUM_LIT:0> ] , dtype = np . int8 ) , np . uint8 ) <EOL> assert_equal ( get_slope_inter ( aw ) , ( - <NUM_LIT:1.0> , <NUM_LIT:0.0> ) ) <EOL> aw = SAW ( npa ( [ - <NUM_LIT> , <NUM_LIT:0> ] , dtype = np . int16 ) , np . uint8 ) <EOL> assert_equal ( get_slope_inter ( aw ) , ( - <NUM_LIT> , <NUM_LIT:0.0> ) ) <EOL> aw = SAW ( npa ( [ - <NUM_LIT:2> , <NUM_LIT:0> ] , dtype = np . float32 ) , np . uint8 ) <EOL> assert_not_equal ( get_slope_inter ( aw ) , ( - <NUM_LIT:1.0> , <NUM_LIT:0.0> ) ) <EOL> aw = SIAW ( npa ( [ - <NUM_LIT:1> , <NUM_LIT:1> ] , dtype = np . int8 ) , np . uint8 ) <EOL> assert_equal ( get_slope_inter ( aw ) , ( <NUM_LIT:1.0> , - <NUM_LIT:1.0> ) ) <EOL> assert_raises ( WriterError , SAW , npa ( [ - <NUM_LIT:1> , <NUM_LIT:1> ] , dtype = np . int8 ) , np . uint8 ) <EOL> aw = SIAW ( npa ( [ - <NUM_LIT:1> , <NUM_LIT:255> ] , dtype = np . int16 ) , np . uint8 ) <EOL> slope_inter = get_slope_inter ( aw ) <EOL> assert_not_equal ( slope_inter , ( <NUM_LIT:1.0> , - <NUM_LIT:1.0> ) ) <EOL> def test_resets ( ) : <EOL> for klass , inp , outp in ( ( SlopeInterArrayWriter , ( <NUM_LIT:1> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT:1.0> ) ) , <EOL> ( SlopeArrayWriter , ( <NUM_LIT:0> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT:0.0> ) ) ) : <EOL> arr = np . array ( inp ) <EOL> outp = np . array ( outp ) <EOL> aw = klass ( arr , np . uint8 ) <EOL> assert_array_equal ( get_slope_inter ( aw ) , outp ) <EOL> aw . calc_scale ( ) <EOL> assert_array_equal ( get_slope_inter ( aw ) , outp ) <EOL> aw . calc_scale ( force = True ) <EOL> assert_array_equal ( get_slope_inter ( aw ) , outp ) <EOL> aw . array [ : ] = aw . array * <NUM_LIT:2> <EOL> aw . calc_scale ( ) <EOL> assert_array_equal ( get_slope_inter ( aw ) , outp ) <EOL> aw . calc_scale ( force = True ) <EOL> assert_array_equal ( get_slope_inter ( aw ) , outp * <NUM_LIT:2> ) <EOL> aw . reset ( ) <EOL> assert_array_equal ( get_slope_inter ( aw ) , ( <NUM_LIT:1.0> , <NUM_LIT:0.0> ) ) <EOL> def test_no_offset_scale ( ) : <EOL> SAW = SlopeArrayWriter <EOL> for data in ( ( - <NUM_LIT> , <NUM_LIT> ) , <EOL> ( - <NUM_LIT> , <NUM_LIT> ) , <EOL> ( - <NUM_LIT> , - <NUM_LIT> ) , <EOL> ( - <NUM_LIT> , <NUM_LIT:0> ) , <EOL> ( - <NUM_LIT> , - <NUM_LIT:1> ) , <EOL> ( <NUM_LIT> , <NUM_LIT> ) , <EOL> ( - <NUM_LIT> , <NUM_LIT> ) ) : <EOL> aw = SAW ( np . array ( data , dtype = np . float32 ) , np . int8 ) <EOL> assert_equal ( aw . slope , <NUM_LIT:1.0> ) <EOL> aw = SAW ( np . array ( [ - <NUM_LIT> , <NUM_LIT> * <NUM_LIT> ] , dtype = np . float32 ) , np . int8 ) <EOL> assert_equal ( aw . slope , <NUM_LIT:2> ) <EOL> aw = SAW ( np . array ( [ - <NUM_LIT> * <NUM_LIT> , <NUM_LIT> ] , dtype = np . float32 ) , np . int8 ) <EOL> assert_equal ( aw . slope , <NUM_LIT:2> ) <EOL> n = - <NUM_LIT:2> ** <NUM_LIT:15> <EOL> aw = SAW ( np . array ( [ n , n ] , dtype = np . int16 ) , np . uint8 ) <EOL> assert_array_almost_equal ( aw . slope , n / <NUM_LIT> , <NUM_LIT:5> ) <EOL> def test_with_offset_scale ( ) : <EOL> SIAW = SlopeInterArrayWriter <EOL> aw = SIAW ( np . array ( [ <NUM_LIT:0> , <NUM_LIT> ] , dtype = np . int8 ) , np . uint8 ) <EOL> assert_equal ( ( aw . slope , aw . inter ) , ( <NUM_LIT:1> , <NUM_LIT:0> ) ) <EOL> aw = SIAW ( np . array ( [ - <NUM_LIT:1> , <NUM_LIT> ] , dtype = np . int8 ) , np . uint8 ) <EOL> assert_equal ( ( aw . slope , aw . inter ) , ( <NUM_LIT:1> , - <NUM_LIT:1> ) ) <EOL> aw = SIAW ( np . array ( [ - <NUM_LIT:1> , <NUM_LIT> ] , dtype = np . int16 ) , np . uint8 ) <EOL> assert_equal ( ( aw . slope , aw . inter ) , ( <NUM_LIT:1> , - <NUM_LIT:1> ) ) <EOL> aw = SIAW ( np . array ( [ - <NUM_LIT:1> , <NUM_LIT:255> ] , dtype = np . int16 ) , np . uint8 ) <EOL> assert_not_equal ( ( aw . slope , aw . inter ) , ( <NUM_LIT:1> , - <NUM_LIT:1> ) ) <EOL> aw = SIAW ( np . array ( [ - <NUM_LIT> , - <NUM_LIT:2> ] , dtype = np . int16 ) , np . uint8 ) <EOL> assert_equal ( ( aw . slope , aw . inter ) , ( <NUM_LIT:1> , - <NUM_LIT> ) ) <EOL> aw = SIAW ( np . array ( [ - <NUM_LIT> , - <NUM_LIT:2> ] , dtype = np . int16 ) , np . int8 ) <EOL> assert_equal ( ( aw . slope , aw . inter ) , ( <NUM_LIT:1> , - <NUM_LIT> ) ) <EOL> def test_io_scaling ( ) : <EOL> bio = BytesIO ( ) <EOL> for in_type , out_type in itertools . product ( <EOL> ( np . int16 , np . uint16 , np . float32 ) , <EOL> ( np . int8 , np . uint8 , np . int16 , np . uint16 ) ) : <EOL> out_dtype = np . dtype ( out_type ) <EOL> info = type_info ( in_type ) <EOL> imin , imax = info [ '<STR_LIT>' ] , info [ '<STR_LIT>' ] <EOL> if imin == <NUM_LIT:0> : <EOL> val_tuples = ( ( <NUM_LIT:0> , imax ) , <EOL> ( <NUM_LIT:100> , imax ) ) <EOL> else : <EOL> val_tuples = ( ( imin , <NUM_LIT:0> , imax ) , <EOL> ( imin , <NUM_LIT:0> ) , <EOL> ( <NUM_LIT:0> , imax ) , <EOL> ( imin , <NUM_LIT:100> , imax ) ) <EOL> if imin != <NUM_LIT:0> : <EOL> val_tuples += ( ( imin , <NUM_LIT:0> ) , <EOL> ( <NUM_LIT:0> , imax ) ) <EOL> for vals in val_tuples : <EOL> arr = np . array ( vals , dtype = in_type ) <EOL> aw = SlopeInterArrayWriter ( arr , out_dtype ) <EOL> aw . to_fileobj ( bio ) <EOL> arr2 = array_from_file ( arr . shape , out_dtype , bio ) <EOL> arr3 = apply_read_scaling ( arr2 , aw . slope , aw . inter ) <EOL> max_miss = np . abs ( aw . slope ) / <NUM_LIT> <EOL> abs_err = np . abs ( arr - arr3 ) <EOL> assert_true ( np . all ( abs_err <= max_miss ) ) <EOL> if out_type in UINT_TYPES and <NUM_LIT:0> in ( min ( arr ) , max ( arr ) ) : <EOL> assert_true ( min ( abs_err ) == abs_err [ arr == <NUM_LIT:0> ] ) <EOL> bio . truncate ( <NUM_LIT:0> ) <EOL> bio . seek ( <NUM_LIT:0> ) <EOL> def test_input_ranges ( ) : <EOL> arr = np . arange ( - <NUM_LIT> , <NUM_LIT> , <NUM_LIT:10> , dtype = np . float ) <EOL> bio = BytesIO ( ) <EOL> working_type = np . float32 <EOL> work_eps = np . finfo ( working_type ) . eps <EOL> for out_type , offset in itertools . product ( <EOL> IUINT_TYPES , <EOL> range ( - <NUM_LIT:1000> , <NUM_LIT:1000> , <NUM_LIT:100> ) ) : <EOL> aw = SlopeInterArrayWriter ( arr , out_type ) <EOL> aw . to_fileobj ( bio ) <EOL> arr2 = array_from_file ( arr . shape , out_type , bio ) <EOL> arr3 = apply_read_scaling ( arr2 , aw . slope , aw . inter ) <EOL> max_miss = np . abs ( aw . slope ) / working_type ( <NUM_LIT> ) + work_eps * <NUM_LIT:10> <EOL> abs_err = np . abs ( arr - arr3 ) <EOL> max_err = np . abs ( arr ) * work_eps + max_miss <EOL> assert_true ( np . all ( abs_err <= max_err ) ) <EOL> if out_type in UINT_TYPES and <NUM_LIT:0> in ( min ( arr ) , max ( arr ) ) : <EOL> assert_true ( min ( abs_err ) == abs_err [ arr == <NUM_LIT:0> ] ) <EOL> bio . truncate ( <NUM_LIT:0> ) <EOL> bio . seek ( <NUM_LIT:0> ) <EOL> def test_nan2zero ( ) : <EOL> arr = np . array ( [ np . nan , <NUM_LIT> ] , dtype = np . float32 ) <EOL> for awt , kwargs in ( ( ArrayWriter , dict ( check_scaling = False ) ) , <EOL> ( SlopeArrayWriter , dict ( calc_scale = False ) ) , <EOL> ( SlopeInterArrayWriter , dict ( calc_scale = False ) ) ) : <EOL> aw = awt ( arr , np . float32 , ** kwargs ) <EOL> data_back = round_trip ( aw ) <EOL> assert_array_equal ( np . isnan ( data_back ) , [ True , False ] ) <EOL> with error_warnings ( ) : <EOL> assert_raises ( DeprecationWarning , <EOL> aw . to_fileobj , BytesIO ( ) , '<STR_LIT:F>' , True ) <EOL> assert_raises ( DeprecationWarning , <EOL> aw . to_fileobj , BytesIO ( ) , '<STR_LIT:F>' , nan2zero = True ) <EOL> assert_raises ( WriterError , aw . to_fileobj , BytesIO ( ) , '<STR_LIT:F>' , False ) <EOL> aw = awt ( arr , np . float32 , nan2zero = True , ** kwargs ) <EOL> data_back = round_trip ( aw ) <EOL> assert_array_equal ( np . isnan ( data_back ) , [ True , False ] ) <EOL> aw = awt ( arr , np . int32 , ** kwargs ) <EOL> data_back = round_trip ( aw ) <EOL> assert_array_equal ( data_back , [ <NUM_LIT:0> , <NUM_LIT> ] ) <EOL> aw = awt ( arr , np . int32 , nan2zero = False , ** kwargs ) <EOL> data_back = round_trip ( aw ) <EOL> astype_res = np . array ( np . nan ) . astype ( np . int32 ) <EOL> assert_array_equal ( data_back , [ astype_res , <NUM_LIT> ] ) <EOL> with error_warnings ( ) : <EOL> assert_raises ( DeprecationWarning , <EOL> aw . to_fileobj , BytesIO ( ) , '<STR_LIT:F>' , False ) <EOL> assert_raises ( DeprecationWarning , <EOL> aw . to_fileobj , BytesIO ( ) , '<STR_LIT:F>' , nan2zero = False ) <EOL> assert_raises ( WriterError , aw . to_fileobj , BytesIO ( ) , '<STR_LIT:F>' , True ) <EOL> def test_byte_orders ( ) : <EOL> arr = np . arange ( <NUM_LIT:10> , dtype = np . int32 ) <EOL> for tp in ( np . uint64 , np . float , np . complex ) : <EOL> dt = np . dtype ( tp ) <EOL> for code in '<STR_LIT>' : <EOL> ndt = dt . newbyteorder ( code ) <EOL> for klass in ( SlopeInterArrayWriter , SlopeArrayWriter , <EOL> ArrayWriter ) : <EOL> aw = klass ( arr , ndt ) <EOL> data_back = round_trip ( aw ) <EOL> assert_array_almost_equal ( arr , data_back ) <EOL> def test_writers_roundtrip ( ) : <EOL> ndt = np . dtype ( np . float ) <EOL> arr = np . arange ( <NUM_LIT:3> , dtype = ndt ) <EOL> aw = SlopeInterArrayWriter ( arr , ndt , calc_scale = False ) <EOL> aw . inter = <NUM_LIT:1.0> <EOL> data_back = round_trip ( aw ) <EOL> assert_array_equal ( data_back , arr ) <EOL> aw . slope = <NUM_LIT> <EOL> data_back = round_trip ( aw ) <EOL> assert_array_equal ( data_back , arr ) <EOL> aw = SlopeInterArrayWriter ( arr + np . nan , np . int32 ) <EOL> data_back = round_trip ( aw ) <EOL> assert_array_equal ( data_back , np . zeros ( arr . shape ) ) <EOL> arr [ <NUM_LIT:0> ] = np . inf <EOL> aw = SlopeInterArrayWriter ( arr , np . int32 ) <EOL> data_back = round_trip ( aw ) <EOL> assert_array_almost_equal ( data_back , [ <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> def test_to_float ( ) : <EOL> start , stop = <NUM_LIT:0> , <NUM_LIT:100> <EOL> for in_type in NUMERIC_TYPES : <EOL> step = <NUM_LIT:1> if in_type in IUINT_TYPES else <NUM_LIT:0.5> <EOL> info = type_info ( in_type ) <EOL> mn , mx = info [ '<STR_LIT>' ] , info [ '<STR_LIT>' ] <EOL> arr = np . arange ( start , stop , step , dtype = in_type ) <EOL> arr [ <NUM_LIT:0> ] = mn <EOL> arr [ - <NUM_LIT:1> ] = mx <EOL> for out_type in CFLOAT_TYPES : <EOL> out_info = type_info ( out_type ) <EOL> for klass in ( SlopeInterArrayWriter , SlopeArrayWriter , <EOL> ArrayWriter ) : <EOL> if in_type in COMPLEX_TYPES and out_type in FLOAT_TYPES : <EOL> assert_raises ( WriterError , klass , arr , out_type ) <EOL> continue <EOL> aw = klass ( arr , out_type ) <EOL> assert_true ( aw . array is arr ) <EOL> assert_equal ( aw . out_dtype , out_type ) <EOL> arr_back = round_trip ( aw ) <EOL> assert_array_equal ( arr . astype ( out_type ) , arr_back ) <EOL> out_min , out_max = out_info [ '<STR_LIT>' ] , out_info [ '<STR_LIT>' ] <EOL> assert_true ( np . all ( arr_back [ arr > out_max ] == np . inf ) ) <EOL> assert_true ( np . all ( arr_back [ arr < out_min ] == - np . inf ) ) <EOL> def test_dumber_writers ( ) : <EOL> arr = np . arange ( <NUM_LIT:10> , dtype = np . float64 ) <EOL> aw = SlopeArrayWriter ( arr ) <EOL> aw . slope = <NUM_LIT> <EOL> assert_equal ( aw . slope , <NUM_LIT> ) <EOL> assert_raises ( AttributeError , getattr , aw , '<STR_LIT>' ) <EOL> aw = ArrayWriter ( arr ) <EOL> assert_raises ( AttributeError , getattr , aw , '<STR_LIT>' ) <EOL> assert_raises ( AttributeError , getattr , aw , '<STR_LIT>' ) <EOL> assert_raises ( WriterError , ArrayWriter , arr , np . int16 ) <EOL> def test_writer_maker ( ) : <EOL> arr = np . arange ( <NUM_LIT:10> , dtype = np . float64 ) <EOL> aw = make_array_writer ( arr , np . float64 ) <EOL> assert_true ( isinstance ( aw , SlopeInterArrayWriter ) ) <EOL> aw = make_array_writer ( arr , np . float64 , True , True ) <EOL> assert_true ( isinstance ( aw , SlopeInterArrayWriter ) ) <EOL> aw = make_array_writer ( arr , np . float64 , True , False ) <EOL> assert_true ( isinstance ( aw , SlopeArrayWriter ) ) <EOL> aw = make_array_writer ( arr , np . float64 , False , False ) <EOL> assert_true ( isinstance ( aw , ArrayWriter ) ) <EOL> assert_raises ( ValueError , make_array_writer , arr , np . float64 , False ) <EOL> assert_raises ( ValueError , make_array_writer , arr , np . float64 , False , True ) <EOL> aw = make_array_writer ( arr , np . int16 , calc_scale = False ) <EOL> assert_equal ( ( aw . slope , aw . inter ) , ( <NUM_LIT:1> , <NUM_LIT:0> ) ) <EOL> aw . calc_scale ( ) <EOL> slope , inter = aw . slope , aw . inter <EOL> assert_false ( ( slope , inter ) == ( <NUM_LIT:1> , <NUM_LIT:0> ) ) <EOL> aw = make_array_writer ( arr , np . int16 ) <EOL> assert_equal ( ( aw . slope , aw . inter ) , ( slope , inter ) ) <EOL> aw = make_array_writer ( arr , np . int16 , calc_scale = True ) <EOL> assert_equal ( ( aw . slope , aw . inter ) , ( slope , inter ) ) <EOL> def test_float_int_min_max ( ) : <EOL> for in_dt in FLOAT_TYPES : <EOL> finf = type_info ( in_dt ) <EOL> arr = np . array ( [ finf [ '<STR_LIT>' ] , finf [ '<STR_LIT>' ] ] , dtype = in_dt ) <EOL> if not np . all ( np . isfinite ( arr ) ) : <EOL> print ( '<STR_LIT>' % in_dt ) <EOL> continue <EOL> for out_dt in IUINT_TYPES : <EOL> try : <EOL> with suppress_warnings ( ) : <EOL> aw = SlopeInterArrayWriter ( arr , out_dt ) <EOL> except ScalingError : <EOL> continue <EOL> arr_back_sc = round_trip ( aw ) <EOL> assert_true ( np . allclose ( arr , arr_back_sc ) ) <EOL> def test_int_int_min_max ( ) : <EOL> eps = np . finfo ( np . float64 ) . eps <EOL> rtol = <NUM_LIT> <EOL> for in_dt in IUINT_TYPES : <EOL> iinf = np . iinfo ( in_dt ) <EOL> arr = np . array ( [ iinf . min , iinf . max ] , dtype = in_dt ) <EOL> for out_dt in IUINT_TYPES : <EOL> try : <EOL> aw = SlopeInterArrayWriter ( arr , out_dt ) <EOL> except ScalingError : <EOL> continue <EOL> arr_back_sc = round_trip ( aw ) <EOL> adiff = int_abs ( arr - arr_back_sc ) <EOL> rdiff = adiff / ( arr + eps ) <EOL> assert_true ( np . all ( rdiff < rtol ) ) <EOL> def test_int_int_slope ( ) : <EOL> eps = np . finfo ( np . float64 ) . eps <EOL> rtol = <NUM_LIT> <EOL> for in_dt in IUINT_TYPES : <EOL> iinf = np . iinfo ( in_dt ) <EOL> for out_dt in IUINT_TYPES : <EOL> kinds = np . dtype ( in_dt ) . kind + np . dtype ( out_dt ) . kind <EOL> if kinds in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> arrs = ( np . array ( [ iinf . min , iinf . max ] , dtype = in_dt ) , ) <EOL> elif kinds == '<STR_LIT>' : <EOL> arrs = ( np . array ( [ iinf . min , <NUM_LIT:0> ] , dtype = in_dt ) , <EOL> np . array ( [ <NUM_LIT:0> , iinf . max ] , dtype = in_dt ) ) <EOL> for arr in arrs : <EOL> try : <EOL> aw = SlopeArrayWriter ( arr , out_dt ) <EOL> except ScalingError : <EOL> continue <EOL> assert_false ( aw . slope == <NUM_LIT:0> ) <EOL> arr_back_sc = round_trip ( aw ) <EOL> adiff = int_abs ( arr - arr_back_sc ) <EOL> rdiff = adiff / ( arr + eps ) <EOL> assert_true ( np . all ( rdiff < rtol ) ) <EOL> def test_float_int_spread ( ) : <EOL> powers = np . arange ( - <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:0.5> ) <EOL> arr = np . concatenate ( ( - <NUM_LIT:10> ** powers , <NUM_LIT:10> ** powers ) ) <EOL> for in_dt in ( np . float32 , np . float64 ) : <EOL> arr_t = arr . astype ( in_dt ) <EOL> for out_dt in IUINT_TYPES : <EOL> aw = SlopeInterArrayWriter ( arr_t , out_dt ) <EOL> arr_back_sc = round_trip ( aw ) <EOL> max_miss = rt_err_estimate ( arr_t , <EOL> arr_back_sc . dtype , <EOL> aw . slope , <EOL> aw . inter ) <EOL> diff = np . abs ( arr_t - arr_back_sc ) <EOL> rdiff = diff / np . abs ( arr_t ) <EOL> assert_true ( np . all ( ( diff <= max_miss ) | ( rdiff <= <NUM_LIT> ) ) ) <EOL> def rt_err_estimate ( arr_t , out_dtype , slope , inter ) : <EOL> slope = <NUM_LIT:1> if slope is None else slope <EOL> inter = <NUM_LIT:1> if inter is None else inter <EOL> max_int_miss = slope / <NUM_LIT> <EOL> flt_there = ( arr_t - inter ) / slope <EOL> flt_back = flt_there . astype ( out_dtype ) * slope + inter <EOL> max_flt_miss = np . abs ( arr_t - flt_back ) . max ( ) <EOL> return max_int_miss + max_flt_miss <EOL> def test_rt_bias ( ) : <EOL> rng = np . random . RandomState ( <NUM_LIT> ) <EOL> mu , std , count = <NUM_LIT:100> , <NUM_LIT:10> , <NUM_LIT:100> <EOL> arr = rng . normal ( mu , std , size = ( count , ) ) <EOL> eps = np . finfo ( np . float32 ) . eps <EOL> for in_dt in ( np . float32 , np . float64 ) : <EOL> arr_t = arr . astype ( in_dt ) <EOL> for out_dt in IUINT_TYPES : <EOL> aw = SlopeInterArrayWriter ( arr_t , out_dt ) <EOL> arr_back_sc = round_trip ( aw ) <EOL> bias = np . mean ( arr_t - arr_back_sc ) <EOL> max_miss = rt_err_estimate ( arr_t , <EOL> arr_back_sc . dtype , <EOL> aw . slope , <EOL> aw . inter ) <EOL> bias_thresh = np . max ( [ max_miss / np . sqrt ( count ) , eps ] ) <EOL> assert_true ( np . abs ( bias ) < bias_thresh ) <EOL> def test_nan2zero_scaling ( ) : <EOL> for awt , in_dt , out_dt , sign in itertools . product ( <EOL> ( SlopeArrayWriter , SlopeInterArrayWriter ) , <EOL> FLOAT_TYPES , <EOL> IUINT_TYPES , <EOL> ( - <NUM_LIT:1> , <NUM_LIT:1> ) , <EOL> ) : <EOL> in_info = type_info ( in_dt ) <EOL> out_info = type_info ( out_dt ) <EOL> if in_info [ '<STR_LIT>' ] == <NUM_LIT:0> and sign == - <NUM_LIT:1> : <EOL> continue <EOL> mx = min ( in_info [ '<STR_LIT>' ] , out_info [ '<STR_LIT>' ] * <NUM_LIT> , <NUM_LIT:2> ** <NUM_LIT:32> ) <EOL> vals = [ np . nan ] + [ <NUM_LIT:100> , mx ] <EOL> nan_arr = np . array ( vals , dtype = in_dt ) * sign <EOL> nan_arr_0 = np . array ( [ <NUM_LIT:0> ] + vals , dtype = in_dt ) * sign <EOL> zero_arr = np . nan_to_num ( nan_arr ) <EOL> nan_aw = awt ( nan_arr , out_dt , nan2zero = True ) <EOL> back_nan = round_trip ( nan_aw ) * float ( sign ) <EOL> nan_0_aw = awt ( nan_arr_0 , out_dt , nan2zero = True ) <EOL> back_nan_0 = round_trip ( nan_0_aw ) * float ( sign ) <EOL> zero_aw = awt ( zero_arr , out_dt , nan2zero = True ) <EOL> back_zero = round_trip ( zero_aw ) * float ( sign ) <EOL> assert_true ( np . allclose ( back_nan [ <NUM_LIT:1> : ] , back_zero [ <NUM_LIT:1> : ] ) ) <EOL> assert_array_equal ( back_nan [ <NUM_LIT:1> : ] , back_nan_0 [ <NUM_LIT:2> : ] ) <EOL> assert_true ( np . abs ( back_nan [ <NUM_LIT:0> ] - back_zero [ <NUM_LIT:0> ] ) < <NUM_LIT> ) <EOL> assert_equal ( * back_nan_0 [ : <NUM_LIT:2> ] ) <EOL> def test_finite_range_nan ( ) : <EOL> for in_arr , res in ( <EOL> ( [ [ - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> ] , [ np . inf , np . nan , - np . inf ] ] , ( - <NUM_LIT:1> , <NUM_LIT:1> ) ) , <EOL> ( np . array ( [ [ - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> ] , [ np . inf , np . nan , - np . inf ] ] ) , ( - <NUM_LIT:1> , <NUM_LIT:1> ) ) , <EOL> ( [ [ np . nan ] , [ np . nan ] ] , ( np . inf , - np . inf ) ) , <EOL> ( np . zeros ( ( <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ) ) + np . nan , ( np . inf , - np . inf ) ) , <EOL> ( [ [ - np . inf ] , [ np . inf ] ] , ( np . inf , - np . inf ) ) , <EOL> ( np . zeros ( ( <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ) ) + np . inf , ( np . inf , - np . inf ) ) , <EOL> ( [ [ np . nan , - <NUM_LIT:1> , <NUM_LIT:2> ] , [ - <NUM_LIT:2> , np . nan , <NUM_LIT:1> ] ] , ( - <NUM_LIT:2> , <NUM_LIT:2> ) ) , <EOL> ( [ [ np . nan , - np . inf , <NUM_LIT:2> ] , [ - <NUM_LIT:2> , np . nan , np . inf ] ] , ( - <NUM_LIT:2> , <NUM_LIT:2> ) ) , <EOL> ( [ [ - np . inf , <NUM_LIT:2> ] , [ np . nan , <NUM_LIT:1> ] ] , ( <NUM_LIT:1> , <NUM_LIT:2> ) ) , <EOL> ( [ [ np . nan , - np . inf , <NUM_LIT:2> ] , [ - <NUM_LIT:2> , np . nan , np . inf ] ] , ( - <NUM_LIT:2> , <NUM_LIT:2> ) ) , <EOL> ( [ np . nan ] , ( np . inf , - np . inf ) ) , <EOL> ( [ np . inf ] , ( np . inf , - np . inf ) ) , <EOL> ( [ - np . inf ] , ( np . inf , - np . inf ) ) , <EOL> ( [ np . inf , <NUM_LIT:1> ] , ( <NUM_LIT:1> , <NUM_LIT:1> ) ) , <EOL> ( [ - np . inf , <NUM_LIT:1> ] , ( <NUM_LIT:1> , <NUM_LIT:1> ) ) , <EOL> ( [ [ ] , [ ] ] , ( np . inf , - np . inf ) ) , <EOL> ( np . array ( [ [ - <NUM_LIT:3> , <NUM_LIT:0> , <NUM_LIT:1> ] , [ <NUM_LIT:2> , - <NUM_LIT:1> , <NUM_LIT:4> ] ] , dtype = np . int ) , ( - <NUM_LIT:3> , <NUM_LIT:4> ) ) , <EOL> ( np . array ( [ [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> ] , [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ] , dtype = np . uint ) , ( <NUM_LIT:0> , <NUM_LIT:4> ) ) , <EOL> ( [ <NUM_LIT:0.> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] , ( <NUM_LIT:0> , <NUM_LIT:3> ) ) , <EOL> ( [ [ np . nan , - <NUM_LIT:1> - <NUM_LIT> , <NUM_LIT:2> ] , [ - <NUM_LIT:2> , np . nan , <NUM_LIT:1> + <NUM_LIT> ] ] , ( - <NUM_LIT:2> , <NUM_LIT:2> ) ) , <EOL> ( [ [ np . nan , - <NUM_LIT:1> , <NUM_LIT:2> - <NUM_LIT> ] , [ - <NUM_LIT:2> + <NUM_LIT> , np . nan , <NUM_LIT:1> ] ] , ( - <NUM_LIT:2> + <NUM_LIT> , <NUM_LIT:2> - <NUM_LIT> ) ) , <EOL> ) : <EOL> for awt , kwargs in ( ( ArrayWriter , dict ( check_scaling = False ) ) , <EOL> ( SlopeArrayWriter , { } ) , <EOL> ( SlopeArrayWriter , dict ( calc_scale = False ) ) , <EOL> ( SlopeInterArrayWriter , { } ) , <EOL> ( SlopeInterArrayWriter , dict ( calc_scale = False ) ) ) : <EOL> for out_type in NUMERIC_TYPES : <EOL> has_nan = np . any ( np . isnan ( in_arr ) ) <EOL> try : <EOL> aw = awt ( in_arr , out_type , ** kwargs ) <EOL> except WriterError : <EOL> continue <EOL> assert_equal ( aw . has_nan , has_nan ) <EOL> assert_equal ( aw . finite_range ( ) , res ) <EOL> aw = awt ( in_arr , out_type , ** kwargs ) <EOL> assert_equal ( aw . finite_range ( ) , res ) <EOL> assert_equal ( aw . has_nan , has_nan ) <EOL> in_arr = np . array ( in_arr ) <EOL> if in_arr . dtype . kind == '<STR_LIT:f>' : <EOL> c_arr = in_arr . astype ( np . complex ) <EOL> try : <EOL> aw = awt ( c_arr , out_type , ** kwargs ) <EOL> except WriterError : <EOL> continue <EOL> aw = awt ( c_arr , out_type , ** kwargs ) <EOL> assert_equal ( aw . has_nan , has_nan ) <EOL> assert_equal ( aw . finite_range ( ) , res ) <EOL> a = np . array ( [ [ <NUM_LIT:1.> , <NUM_LIT:0> , <NUM_LIT:1> ] , [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ] ) . view ( [ ( '<STR_LIT>' , '<STR_LIT:f>' ) ] ) <EOL> aw = awt ( a , a . dtype , ** kwargs ) <EOL> assert_raises ( TypeError , aw . finite_range ) <EOL> assert_false ( aw . has_nan ) </s>
