code: def _squared_loss_and_spatial_grad(X, y, w, mask, grad_weight):
      """Compute the squared loss (data fidelity term) + squared l2 norm \
      of gradient (penalty term).
  
      Parameters
      ----------
      X : ndarray, shape (n_samples, n_features)
          Design matrix.
  
      y : ndarray, shape (n_samples,)
          Target / response vector.
  
      w : ndarray shape (n_features,)
          Unmasked, ravelized weights map.
  
      grad_weight: float
          l1_ratio * alpha.
  
      Returns
      -------
      float
          Value of Graph-Net objective.
      """
      data_section = np.dot(X, w) - y
      grad_buffer = np.zeros(mask.shape)
      grad_buffer[mask] = w
      grad_mask = np.tile(mask, [mask.ndim] + [1] * mask.ndim)
      grad_section = gradient(grad_buffer)[grad_mask]
      return 0.5 * (
          np.dot(data_section, data_section)
          + grad_weight * np.dot(grad_section, grad_section)
      )
  
file_path: nilearn/nilearn/decoding/space_net_solvers.py
imports: from math import sqrt
  import numpy
  from nilearn.masking import unmask_from_to_3d_array
  from ._objective_functions import divergence, gradient, gradient_id, logistic_loss, logistic_loss_grad, logistic_loss_lipschitz_constant, spectral_norm_squared, squared_loss, squared_loss_grad
  from ._proximal_operators import prox_l1, prox_l1_with_intercept, prox_tvl1, prox_tvl1_with_intercept
  from .fista import mfista
label_desc: Use image node_id 1 for calling a global function with example usage: _squared_loss_and_spatial_grad(X, y, w, mask, grad_weight) and returns: unknown