#NEWLINE# def _choose_algorithm( self , algorithm , metric ) : #NEWLINE# #INDENT# if ( algorithm == 'auto' ) : #NEWLINE# #INDENT# if ( metric in KDTree . valid_metrics ) : #NEWLINE# #INDENT# return 'kd_tree' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( metric in BallTree . valid_metrics ) : #NEWLINE# #INDENT# return 'ball_tree' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( "invalid metric: '{0}'" . format ( metric ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( algorithm in TREE_DICT ) : #NEWLINE# #INDENT# if ( metric not in TREE_DICT [ algorithm ] . valid_metrics ) : #NEWLINE# #INDENT# raise ValueError ( "invalid metric for {0}: '{1}'" . format ( TREE_DICT [ algorithm ] , metric ) ) #NEWLINE# #UNINDENT# return algorithm #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( "invalid algorithm: '{0}'" . format ( algorithm ) )