code: def _check_weights(weights, pb, X, n_groups):
      """Handle weights cases."""
      if weights is None:
          n_weights = n_groups if pb == GRPLASSO else X.shape[1]
          weights = np.ones(n_weights, dtype=X.dtype)
      elif (weights <= 0).any():
          raise ValueError("0 or negative weights are not supported.")
      else:
          expected_n_weights = (
              n_groups if pb == GRPLASSO else X.shape[1]
          )
          feat_or_grp = "groups" if pb == GRPLASSO else "features"
  
          if weights.shape[0] != expected_n_weights:
              raise ValueError(
                  f"As many weights as {feat_or_grp} must be passed. "
                  f"Expected {expected_n_weights}, got {weights.shape[0]}."
              )
  
      return weights
  
file_path: celer/celer/homotopy.py
imports: import numpy
  from scipy import sparse
  from numpy.linalg import norm
  from sklearn.utils import check_array
  from sklearn.linear_model._base import _preprocess_data
  from .lasso_fast import celer
  from .group_fast import celer_grp, dnorm_grp
  from .cython_utils import compute_norms_X_col, compute_Xw
  from .cython_utils import dnorm_enet
  from .multitask_fast import celer_mtl
  from .PN_logreg import newton_celer
label_desc: Use image node_id 2 for calling a global function with example usage: _check_weights(weights, pb, X, n_groups) and returns: weights