#NEWLINE# def _qsturng( p , r , v ) : #NEWLINE# #INDENT# 'scalar version of qsturng' #NEWLINE# global A , p_keys , v_keys #NEWLINE# if ( ( p < 0.1 ) or ( p > 0.999 ) ) : #NEWLINE# #INDENT# raise ValueError ( 'p must be between .1 and .999' ) #NEWLINE# #UNINDENT# if ( p < 0.9 ) : #NEWLINE# #INDENT# if ( v < 2 ) : #NEWLINE# #INDENT# raise ValueError ( 'v must be > 2 when p < .9' ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( v < 1 ) : #NEWLINE# #INDENT# raise ValueError ( 'v must be > 1 when p >= .9' ) #NEWLINE# #UNINDENT# #UNINDENT# p = float ( p ) #NEWLINE# if isinstance ( v , np . ndarray ) : #NEWLINE# #INDENT# v = v . item ( ) #NEWLINE# #UNINDENT# if ( ( p , v ) in A ) : #NEWLINE# #INDENT# y = ( _func ( A [ ( p , v ) ] , p , r , v ) + 1.0 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( p not in p_keys ) and ( v not in ( v_keys + ( [ ] , [ 1 ] ) [ ( p >= 0.9 ) ] ) ) ) : #NEWLINE# #INDENT# ( v0 , v1 , v2 ) = _select_vs ( v , p ) #NEWLINE# ( p0 , p1 , p2 ) = _select_ps ( p ) #NEWLINE# r0_sq = ( _interpolate_p ( p , r , v0 ) ** 2 ) #NEWLINE# r1_sq = ( _interpolate_p ( p , r , v1 ) ** 2 ) #NEWLINE# r2_sq = ( _interpolate_p ( p , r , v2 ) ** 2 ) #NEWLINE# ( v_ , v0_ , v1_ , v2_ ) = ( ( 1.0 / v ) , ( 1.0 / v0 ) , ( 1.0 / v1 ) , ( 1.0 / v2 ) ) #NEWLINE# d2 = ( ( 2.0 * ( ( ( r2_sq - r1_sq ) / ( v2_ - v1_ ) ) - ( ( r0_sq - r1_sq ) / ( v0_ - v1_ ) ) ) ) / ( v2_ - v0_ ) ) #NEWLINE# if ( ( v2_ + v0_ ) >= ( v1_ + v1_ ) ) : #NEWLINE# #INDENT# d1 = ( ( ( r2_sq - r1_sq ) / ( v2_ - v1_ ) ) - ( ( 0.5 * d2 ) * ( v2_ - v1_ ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# d1 = ( ( ( r1_sq - r0_sq ) / ( v1_ - v0_ ) ) + ( ( 0.5 * d2 ) * ( v1_ - v0_ ) ) ) #NEWLINE# #UNINDENT# d0 = r1_sq #NEWLINE# y = math . sqrt ( ( ( ( ( d2 / 2.0 ) * ( ( v_ - v1_ ) ** 2.0 ) ) + ( d1 * ( v_ - v1_ ) ) ) + d0 ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( v not in ( v_keys + ( [ ] , [ 1 ] ) [ ( p >= 0.9 ) ] ) ) : #NEWLINE# #INDENT# y = _interpolate_v ( p , r , v ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( p not in p_keys ) : #NEWLINE# #INDENT# y = _interpolate_p ( p , r , v ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return ( ( math . sqrt ( 2 ) * ( - y ) ) * scipy . stats . t . isf ( ( ( 1.0 + p ) / 2.0 ) , ( v , 1e+38 ) [ ( v > 1e+38 ) ] ) )