def _safe_split(estimator, X, y, indices, train_indices=None):
 if getattr(estimator, '_pairwise', False):
  if (not hasattr(X, 'shape')):
   raise ValueError('Precomputed kernels or affinity matrices have to be passed as arrays or sparse matrices.')
  if (X.shape[0] != X.shape[1]):
   raise ValueError('X should be a square kernel matrix')
  if (train_indices is None):
   X_subset = X[np.ix_(indices, indices)]
  else:
   X_subset = X[np.ix_(indices, train_indices)]
 else:
  X_subset = safe_indexing(X, indices)
 if (y is not None):
  y_subset = safe_indexing(y, indices)
 else:
  y_subset = None
 return (X_subset, y_subset)

def _safe_split ( estimator , X , y , indices , train_indices = None ) : if getattr ( estimator , '_pairwise' , False ) : if ( not hasattr ( X , 'shape' ) ) : raise ValueError ( 'Precomputed kernels or affinity matrices have to be passed as arrays or sparse matrices.' ) if ( X . shape [ 0 ] != X . shape [ 1 ] ) : raise ValueError ( 'X should be a square kernel matrix' ) if ( train_indices is None ) : X_subset = X [ np . ix_ ( indices , indices ) ] else : X_subset = X [ np . ix_ ( indices , train_indices ) ] else : X_subset = safe_indexing ( X , indices ) if ( y is not None ) : y_subset = safe_indexing ( y , indices ) else : y_subset = None return ( X_subset , y_subset )
create subset of dataset and properly handle kernels .