code: def _solve_cholesky_kernel(
      K, y, alpha, sample_weight=None, copy=False
  ):
      # dual_coef = inv(X X^t + alpha*Id) y
      n_samples = K.shape[0]
      n_targets = y.shape[1]
  
      if copy:
          K = K.copy()
  
      alpha = np.atleast_1d(alpha)
      one_alpha = (alpha == alpha[0]).all()
      has_sw = isinstance(
          sample_weight, np.ndarray
      ) or sample_weight not in [1.0, None]
  
      if has_sw:
          # Unlike other solvers, we need to support sample_weight directly
          # because K might be a pre-computed kernel.
          sw = np.sqrt(np.atleast_1d(sample_weight))
          y = y * sw[:, np.newaxis]
          K *= np.outer(sw, sw)
  
      if one_alpha:
          # Only one penalty, we can solve multi-target problems in one time.
          K.flat[:: n_samples + 1] += alpha[0]
  
          try:
              # Note: we must use overwrite_a=False in order to be able to
              #       use the fall-back solution below in case a LinAlgError
              #       is raised
              dual_coef = linalg.solve(
                  K, y, sym_pos=True, overwrite_a=False
              )
          except np.linalg.LinAlgError:
              warnings.warn(
                  "Singular matrix in solving dual problem. Using "
                  "least-squares solution instead."
              )
              dual_coef = linalg.lstsq(K, y)[0]
  
          # K is expensive to compute and store in memory so change it back in
          # case it was user-given.
          K.flat[:: n_samples + 1] -= alpha[0]
  
          if has_sw:
              dual_coef *= sw[:, np.newaxis]
  
          return dual_coef
      else:
          # One penalty per target. We need to solve each target separately.
          dual_coefs = np.empty([n_targets, n_samples])
  
          for dual_coef, target, current_alpha in zip(
              dual_coefs, y.T, alpha
          ):
              K.flat[:: n_samples + 1] += current_alpha
  
              dual_coef[:] = linalg.solve(
                  K, target, sym_pos=True, overwrite_a=False
              ).ravel()
  
              K.flat[:: n_samples + 1] -= current_alpha
  
          if has_sw:
              dual_coefs *= sw[np.newaxis, :]
  
          return dual_coefs.T
  
imports: from abc import ABCMeta, abstractmethod
  import warnings
  import numpy
  from scipy import linalg
  from scipy import sparse
  from scipy.sparse import linalg
  from .base import LinearClassifierMixin, LinearModel, _rescale_data
  from .sag import sag_solver
  from ..base import RegressorMixin
  from ..utils.extmath import safe_sparse_dot
  from ..utils.extmath import row_norms
  from ..utils import check_X_y
  from ..utils import check_array
  from ..utils import check_consistent_length
  from ..utils import compute_sample_weight
  from ..utils import column_or_1d
  from ..preprocessing import LabelBinarizer
  from ..model_selection import GridSearchCV
  from ..externals import six
  from ..metrics.scorer import check_scoring
label_desc: Use image node_id 4 for calling a global function with example usage: _solve_cholesky_kernel(K, y, alpha, sample_weight, copy) and returns: dual_coef, dual_coefs