def wrap_penalty(p, fit_linear, linear_penalty=0.):
    """
    tool to account for unity penalty on the linear term of any feature.

    example:
        p = wrap_penalty(derivative, fit_linear=True)(n, coef)

    Parameters
    ----------
    p : callable.
        penalty-matrix-generating function.
    fit_linear : boolean.
        whether the current feature has a linear term or not.
    linear_penalty : float, default: 0.
        penalty on the linear term

    Returns
    -------
    wrapped_p : callable
      modified penalty-matrix-generating function
    """
    def wrapped_p(n, *args):
        if fit_linear:
            if n == 1:
                return sp.sparse.block_diag([linear_penalty], format='csc')
            return sp.sparse.block_diag([linear_penalty,
                                         p(n-1, *args)], format='csc')
        else:
            return p(n, *args)
    return wrapped_p
tool to account for unity penalty on the linear term of any feature.

    example:
        p = wrap_penalty(derivative, fit_linear=True)(n, coef)

    Parameters
    ----------
    p : callable.
        penalty-matrix-generating function.
    fit_linear : boolean.
        whether the current feature has a linear term or not.
    linear_penalty : float, default: 0.
        penalty on the linear term

    Returns
    -------
    wrapped_p : callable
      modified penalty-matrix-generating function