#NEWLINE# def test_delta( ) : #NEWLINE# #INDENT# def __test( width , order , axis , x ) : #NEWLINE# #INDENT# delta = librosa . feature . delta ( x , width = width , order = order , axis = axis , trim = False ) #NEWLINE# delta_t = librosa . feature . delta ( x , width = width , order = order , axis = axis , trim = True ) #NEWLINE# eq_ ( x . shape , delta_t . shape ) #NEWLINE# _s = ( [ slice ( None ) ] * delta . ndim ) #NEWLINE# _s [ axis ] = slice ( ( ( ( - width ) // 2 ) - x . shape [ axis ] ) , ( ( - ( width // 2 ) ) - 1 ) ) #NEWLINE# delta_retrim = delta [ _s ] #NEWLINE# assert np . allclose ( delta_t , delta_retrim ) #NEWLINE# slice_orig = ( [ slice ( None ) ] * x . ndim ) #NEWLINE# slice_out = ( [ slice ( None ) ] * delta . ndim ) #NEWLINE# slice_orig [ axis ] = slice ( ( ( width // 2 ) + 1 ) , ( ( ( - width ) // 2 ) + 1 ) ) #NEWLINE# slice_out [ axis ] = slice ( ( width // 2 ) , ( ( - width ) // 2 ) ) #NEWLINE# assert np . allclose ( ( x + delta_t ) [ slice_out ] , x [ slice_orig ] ) #NEWLINE# #UNINDENT# x = np . vstack ( ( [ np . arange ( 100.0 ) ] * 3 ) ) #NEWLINE# for width in range ( ( - 1 ) , 8 ) : #NEWLINE# #INDENT# for slope in np . linspace ( ( - 2 ) , 2 , num = 6 ) : #NEWLINE# #INDENT# for bias in [ ( - 10 ) , 0 , 10 ] : #NEWLINE# #INDENT# for order in [ 0 , 1 ] : #NEWLINE# #INDENT# for axis in range ( x . ndim ) : #NEWLINE# #INDENT# tf = __test #NEWLINE# if ( ( width < 3 ) or ( np . mod ( width , 2 ) != 1 ) ) : #NEWLINE# #INDENT# tf = raises ( librosa . ParameterError ) ( __test ) #NEWLINE# #UNINDENT# if ( order != 1 ) : #NEWLINE# #INDENT# tf = raises ( librosa . ParameterError ) ( __test ) #NEWLINE# #UNINDENT# ( yield ( tf , width , order , axis , ( ( slope * x ) + bias ) ) )