#NEWLINE# def __init__( self , features , mask = None , specs = [ 'kl' ] , Ks = [ 3 ] , cores = None , algorithm = None , min_dist = None , status_fn = True , progressbar = None , **flann_args ) : #NEWLINE# #INDENT# if ( progressbar is None ) : #NEWLINE# #INDENT# progressbar = ( status_fn is True ) #NEWLINE# #UNINDENT# self . status_fn = status_fn = get_status_fn ( status_fn ) #NEWLINE# self . progressbar = progressbar #NEWLINE# if ( not isinstance ( features , Features ) ) : #NEWLINE# #INDENT# raise TypeError ( 'features should be a Features instance' ) #NEWLINE# #UNINDENT# n_bags = len ( features ) #NEWLINE# dim = features . dim #NEWLINE# self . features = features #NEWLINE# if ( mask is None ) : #NEWLINE# #INDENT# mask = np . ones ( ( n_bags , n_bags ) , dtype = bool ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# mask = np . asarray ( mask ) #NEWLINE# if ( mask . shape != ( n_bags , n_bags ) ) : #NEWLINE# #INDENT# msg = 'mask should be n x n, not {}' #NEWLINE# raise TypeError ( msg . format ( mask . shape ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( mask . dtype . kind != 'b' ) : #NEWLINE# #INDENT# msg = 'mask should be a boolean array, not {}' #NEWLINE# raise TypeError ( msg . format ( mask . dtype ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# self . mask = mask #NEWLINE# self . Ks = Ks = np . array ( np . squeeze ( msg ) , ndmin = 1 , dtype = np . int32 ) #NEWLINE# if ( Ks . ndim != 1 ) : #NEWLINE# #INDENT# msg = 'Ks should be 1-dim, got shape {}' #NEWLINE# raise TypeError ( msg . format ( Ks . shape ) ) #NEWLINE# #UNINDENT# if ( Ks . min ( ) < 1 ) : #NEWLINE# #INDENT# raise ValueError ( 'Ks should be positive; got {}' . format ( Ks . min ( ) ) ) #NEWLINE# #UNINDENT# if ( Ks . max ( ) >= features . _n_pts . min ( ) ) : #NEWLINE# #INDENT# msg = "asked for K = {}, but there's a bag with only {} points" #NEWLINE# raise ValueError ( msg . format ( Ks . max ( ) , features . _n_pts . min ( ) ) ) #NEWLINE# #UNINDENT# self . max_K = Ks . max ( ) #NEWLINE# ( self . funcs , self . metas , self . n_meta_only ) = _parse_specs ( specs , Ks , dim , features . _n_pts ) #NEWLINE# self . specs = specs #NEWLINE# self . save_all_Ks = False #NEWLINE# for func in self . funcs : #NEWLINE# #INDENT# if hasattr ( func , 'k_needed' ) : #NEWLINE# #INDENT# self . max_K = max ( self . max_K , func . k_needed ) #NEWLINE# self . save_all_Ks = True #NEWLINE# #UNINDENT# #UNINDENT# if ( cores is None ) : #NEWLINE# #INDENT# from multiprocessing import cpu_count #NEWLINE# cores = cpu_count ( ) #NEWLINE# #UNINDENT# flann_args [ 'cores' ] = cores #NEWLINE# if ( algorithm is None ) : #NEWLINE# #INDENT# algorithm = pick_flann_algorithm ( dim ) #NEWLINE# #UNINDENT# flann_args [ 'algorithm' ] = algorithm #NEWLINE# try : #NEWLINE# #INDENT# FLANNParameters ( ** flann_args ) #NEWLINE# #UNINDENT# except AttributeError as e : #NEWLINE# #INDENT# msg = '_DivEstimator got an unexpected keyword argument:\n  {}' #NEWLINE# raise TypeError ( msg . format ( e ) ) #NEWLINE# #UNINDENT# self . flann_args = flann_args #NEWLINE# if ( min_dist is None ) : #NEWLINE# #INDENT# min_dist = default_min_dist ( dim ) #NEWLINE# #UNINDENT# self . min_dist = min_dist #NEWLINE# status_fn ( 'kNN processing: K = {} on {!r}' . format ( self . max_K , features ) )