def METHOD_NAME(X, y, w, compute_energy=True, compute_grad=False):
    """Compute the MSE error, and optionally, its gradient too.
    The cost / energy function is
        MSE = .5 * ||y - Xw||^2
    A (1 / n_samples) factor is applied to the MSE.
    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.
    compute_energy : bool, optional (default True)
        If set then energy is computed, otherwise only gradient is computed.
    compute_grad : bool, optional (default False)
        If set then gradient is computed, otherwise only energy is computed.
    Returns
    -------
    energy : float
        Energy (returned if `compute_energy` is set).
    gradient : ndarray, shape (n_features,)
        Gradient of energy (returned if `compute_grad` is set).
    """
    if not compute_energy and not compute_grad:
        raise RuntimeError(
            "At least one of compute_energy or compute_grad must be True."
        )
    residual = np.dot(X, w) - y
    # compute energy
    if compute_energy:
        energy = 0.5 * np.dot(residual, residual)
        if not compute_grad:
            return energy
    grad = np.dot(X.T, residual)
    return (energy, grad) if compute_energy else grad