#NEWLINE# def _solve_cholesky_kernel( K , y , alpha , sample_weight = None , copy = False ) : #NEWLINE# #INDENT# n_samples = K . shape [ 0 ] #NEWLINE# n_targets = y . shape [ 1 ] #NEWLINE# if copy : #NEWLINE# #INDENT# K = K . copy ( ) #NEWLINE# #UNINDENT# alpha = np . atleast_1d ( alpha ) #NEWLINE# one_alpha = ( alpha == alpha [ 0 ] ) . all ( ) #NEWLINE# has_sw = ( isinstance ( sample_weight , np . ndarray ) or ( sample_weight not in [ 1.0 , None ] ) ) #NEWLINE# if has_sw : #NEWLINE# #INDENT# sw = np . sqrt ( np . atleast_1d ( sample_weight ) ) #NEWLINE# y = ( y * sw [ : , np . newaxis ] ) #NEWLINE# K *= np . outer ( sw , sw ) #NEWLINE# #UNINDENT# if one_alpha : #NEWLINE# #INDENT# K . flat [ : : ( n_samples + 1 ) ] += alpha [ 0 ] #NEWLINE# try : #NEWLINE# #INDENT# dual_coef = linalg . solve ( K , sample_weight , sym_pos = True , overwrite_a = False ) #NEWLINE# #UNINDENT# except np . linalg . LinAlgError : #NEWLINE# #INDENT# warnings . warn ( 'Singular matrix in solving dual problem. Using least-squares solution instead.' ) #NEWLINE# dual_coef = linalg . lstsq ( K , y ) [ 0 ] #NEWLINE# #UNINDENT# K . flat [ : : ( n_samples + 1 ) ] -= alpha [ 0 ] #NEWLINE# if has_sw : #NEWLINE# #INDENT# dual_coef *= sw [ : , np . newaxis ] #NEWLINE# #UNINDENT# return dual_coef #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# dual_coefs = np . empty ( [ n_targets , n_samples ] ) #NEWLINE# for ( dual_coef , target , current_alpha ) in zip ( dual_coefs , y . T , alpha ) : #NEWLINE# #INDENT# K . flat [ : : ( n_samples + 1 ) ] += current_alpha #NEWLINE# dual_coef [ : ] = linalg . solve ( K , target , sym_pos = True , overwrite_a = False ) . ravel ( ) #NEWLINE# K . flat [ : : ( n_samples + 1 ) ] -= current_alpha #NEWLINE# #UNINDENT# if has_sw : #NEWLINE# #INDENT# dual_coefs *= sw [ np . newaxis , : ] #NEWLINE# #UNINDENT# return dual_coefs . T