Repository: scikit-learn/scikit-learn
File: sklearn/linear_model/_coordinate_descent.py (Python)

Code before:
                yw = y * sample_weight.reshape(-1, 1)
            else:
                yw = y * sample_weight

        if fit_intercept:
            # Avoid copy of X, i.e. avoid explicitly computing X - X_mean
            if y.ndim > 1:
                Xyw = X.T @ yw - X_mean[:, None] * np.sum(yw, axis=0)
            else:
                Xyw = X.T @ yw - X_mean * np.sum(yw, axis=0)
        else:
            Xyw = X.T @ yw

    if Xyw.ndim == 1:
        Xyw = Xyw[:, np.newaxis]
    if sample_weight is not None:
        n_samples = sample_weight.sum()
    else:
        n_samples = X.shape[0]

    if positive:
        Xyw = np.maximum(0, Xyw)

    # Compute np.max(np.sqrt(np.sum(Xyw**2, axis=1))). We switch sqrt and max to avoid
    # many computations of sqrt.
    alpha_max = np.sqrt(np.max(np.sum(Xyw**2, axis=1))) / (n_samples * l1_ratio)

    if alpha_max <= np.finfo(np.float64).resolution:
        return np.full(n_alphas, np.finfo(np.float64).resolution)

    return np.geomspace(alpha_max, alpha_max * eps, num=n_alphas)


@validate_params(
    {
        "X": ["array-like", "sparse matrix"],
        "y": ["array-like", "sparse matrix"],
        "eps": [Interval(Real, 0, None, closed="neither")],
        "n_alphas": [Interval(Integral, 1, None, closed="left")],
        "alphas": ["array-like", None],
        "precompute": [StrOptions({"auto"}), "boolean", "array-like"],
        "Xy": ["array-like", None],
        "copy_X": ["boolean"],
        "coef_init": ["array-like", None],
        "verbose": ["verbose"],
        "return_n_iter": ["boolean"],
        "positive": ["boolean"],
    },
    prefer_skip_nested_validation=True,
)
def lasso_path(

Review comment (suggestion):
```suggestion
    if not positive:
        # Compute np.max(np.sqrt(np.sum(Xyw**2, axis=1))). We switch sqrt and max to avoid
        # many computations of sqrt.
        alpha_max = np.sqrt(np.max(np.sum(Xyw**2, axis=1))) / (n_samples * l1_ratio)
    else:
        # We may safely assume Xyw.shape[1] == 1, MultiTask estimators do not support positive constraints.
        alpha_max = max(0, np.max(Xyw)) / (n_samples * l1_ratio)
```

Code after:
                yw = y * sample_weight.reshape(-1, 1)
            else:
                yw = y * sample_weight

        if fit_intercept:
            # Avoid copy of X, i.e. avoid explicitly computing X - X_mean
            if y.ndim > 1:
                Xyw = X.T @ yw - X_mean[:, None] * np.sum(yw, axis=0)
            else:
                Xyw = X.T @ yw - X_mean * np.sum(yw, axis=0)
        else:
            Xyw = X.T @ yw

    if Xyw.ndim == 1:
        Xyw = Xyw[:, np.newaxis]
    if sample_weight is not None:
        n_samples = sample_weight.sum()
    else:
        n_samples = X.shape[0]

    if not positive:
        # Compute np.max(np.sqrt(np.sum(Xyw**2, axis=1))). We switch sqrt and max to
        # avoid many computations of sqrt.
        alpha_max = np.sqrt(np.max(np.sum(Xyw**2, axis=1))) / (n_samples * l1_ratio)
    else:
        # We may safely assume Xyw.shape[1] == 1, MultiTask estimators do not support
        # positive constraints.
        alpha_max = max(0, np.max(Xyw)) / (n_samples * l1_ratio)

    if alpha_max <= np.finfo(np.float64).resolution:
        return np.full(n_alphas, np.finfo(np.float64).resolution)

    return np.geomspace(alpha_max, alpha_max * eps, num=n_alphas)


@validate_params(
    {
        "X": ["array-like", "sparse matrix"],
        "y": ["array-like", "sparse matrix"],
        "eps": [Interval(Real, 0, None, closed="neither")],
        "n_alphas": [Interval(Integral, 1, None, closed="left")],
        "alphas": ["array-like", None],
        "precompute": [StrOptions({"auto"}), "boolean", "array-like"],
        "Xy": ["array-like", None],
        "copy_X": ["boolean"],
        "coef_init": ["array-like", None],
        "verbose": ["verbose"],
        "return_n_iter": ["boolean"],
        "positive": ["boolean"],
    },
    prefer_skip_nested_validation=True,