<s> """<STR_LIT>""" <EOL> from __future__ import division , print_function , absolute_import <EOL> import numpy as np <EOL> from . import _interpolate <EOL> def atleast_1d_and_contiguous ( ary , dtype = np . float64 ) : <EOL> return np . atleast_1d ( np . ascontiguousarray ( ary , dtype ) ) <EOL> def nearest ( x , y , new_x ) : <EOL> """<STR_LIT>""" <EOL> shifted_x = np . concatenate ( ( np . array ( [ x [ <NUM_LIT:0> ] - <NUM_LIT:1> ] ) , x [ <NUM_LIT:0> : - <NUM_LIT:1> ] ) ) <EOL> midpoints_of_x = atleast_1d_and_contiguous ( <NUM_LIT> * ( x + shifted_x ) ) <EOL> new_x = atleast_1d_and_contiguous ( new_x ) <EOL> TINY = <NUM_LIT> <EOL> indices = np . searchsorted ( midpoints_of_x , new_x + TINY ) - <NUM_LIT:1> <EOL> indices = np . atleast_1d ( np . clip ( indices , <NUM_LIT:0> , np . Inf ) . astype ( int ) ) <EOL> new_y = np . take ( y , indices , axis = - <NUM_LIT:1> ) <EOL> return new_y <EOL> def linear ( x , y , new_x ) : <EOL> """<STR_LIT>""" <EOL> x = atleast_1d_and_contiguous ( x , np . float64 ) <EOL> y = atleast_1d_and_contiguous ( y , np . float64 ) <EOL> new_x = atleast_1d_and_contiguous ( new_x , np . float64 ) <EOL> if y . ndim > <NUM_LIT:2> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if len ( y . shape ) == <NUM_LIT:2> : <EOL> new_y = np . zeros ( ( y . shape [ <NUM_LIT:0> ] , len ( new_x ) ) , np . float64 ) <EOL> for i in range ( len ( new_y ) ) : <EOL> _interpolate . linear_dddd ( x , y [ i ] , new_x , new_y [ i ] ) <EOL> else : <EOL> new_y = np . zeros ( len ( new_x ) , np . float64 ) <EOL> _interpolate . linear_dddd ( x , y , new_x , new_y ) <EOL> return new_y <EOL> def logarithmic ( x , y , new_x ) : <EOL> """<STR_LIT>""" <EOL> x = atleast_1d_and_contiguous ( x , np . float64 ) <EOL> y = atleast_1d_and_contiguous ( y , np . float64 ) <EOL> new_x = atleast_1d_and_contiguous ( new_x , np . float64 ) <EOL> if y . ndim > <NUM_LIT:2> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if len ( y . shape ) == <NUM_LIT:2> : <EOL> new_y = np . zeros ( ( y . shape [ <NUM_LIT:0> ] , len ( new_x ) ) , np . float64 ) <EOL> for i in range ( len ( new_y ) ) : <EOL> _interpolate . loginterp_dddd ( x , y [ i ] , new_x , new_y [ i ] ) <EOL> else : <EOL> new_y = np . zeros ( len ( new_x ) , np . float64 ) <EOL> _interpolate . loginterp_dddd ( x , y , new_x , new_y ) <EOL> return new_y <EOL> def block_average_above ( x , y , new_x ) : <EOL> """<STR_LIT>""" <EOL> bad_index = None <EOL> x = atleast_1d_and_contiguous ( x , np . float64 ) <EOL> y = atleast_1d_and_contiguous ( y , np . float64 ) <EOL> new_x = atleast_1d_and_contiguous ( new_x , np . float64 ) <EOL> if y . ndim > <NUM_LIT:2> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if len ( y . shape ) == <NUM_LIT:2> : <EOL> new_y = np . zeros ( ( y . shape [ <NUM_LIT:0> ] , len ( new_x ) ) , np . float64 ) <EOL> for i in range ( len ( new_y ) ) : <EOL> bad_index = _interpolate . block_averave_above_dddd ( x , y [ i ] , <EOL> new_x , new_y [ i ] ) <EOL> if bad_index is not None : <EOL> break <EOL> else : <EOL> new_y = np . zeros ( len ( new_x ) , np . float64 ) <EOL> bad_index = _interpolate . block_average_above_dddd ( x , y , new_x , new_y ) <EOL> if bad_index is not None : <EOL> msg = "<STR_LIT>" "<STR_LIT>" % ( bad_index , new_x [ bad_index ] , x [ <NUM_LIT:0> ] , x [ - <NUM_LIT:1> ] ) <EOL> raise ValueError ( msg ) <EOL> return new_y <EOL> def block ( x , y , new_x ) : <EOL> """<STR_LIT>""" <EOL> TINY = <NUM_LIT> <EOL> indices = np . searchsorted ( x , new_x + TINY ) - <NUM_LIT:1> <EOL> indices = np . atleast_1d ( np . clip ( indices , <NUM_LIT:0> , np . Inf ) . astype ( int ) ) <EOL> new_y = np . take ( y , indices , axis = - <NUM_LIT:1> ) <EOL> return new_y </s>
