Exemple #1
0
def test_spline_transformer_periodicity_of_extrapolation(knots, n_knots, degree):
    """Test that the SplineTransformer is periodic for multiple features."""
    X_1 = linspace((-1, 0), (1, 5), 10)
    X_2 = linspace((1, 5), (3, 10), 10)

    splt = SplineTransformer(
        knots=knots, n_knots=n_knots, degree=degree, extrapolation="periodic"
    )
    splt.fit(X_1)

    assert_allclose(splt.transform(X_1), splt.transform(X_2))
Exemple #2
0
def test_linspace():
    """Test that linespace works like np.linespace as of numpy version 1.16."""
    start, stop = 0, 10
    num = 6
    out = linspace(start=start, stop=stop, num=num, endpoint=True)
    assert_array_equal(out, np.array([0.0, 2, 4, 6, 8, 10]))

    start, stop = [0, 100], [10, 1100]
    num = 6
    out = linspace(start=start, stop=stop, num=num, endpoint=True)
    res = np.c_[[0.0, 2, 4, 6, 8, 10], [100, 300, 500, 700, 900, 1100]]
    assert_array_equal(out, res)

    out2 = linspace(start=start, stop=stop, num=num, endpoint=True, axis=1)
    assert_array_equal(out2, out.T)

    out, step = linspace(
        start=start,
        stop=stop,
        num=num,
        endpoint=True,
        retstep=True,
    )
    assert_array_equal(out, res)
    assert_array_equal(step, [2, 200])

    if np_version < parse_version("1.16"):
        with pytest.raises(ValueError):
            linspace(start=[0, 1], stop=10)
    else:
        linspace(start=[0, 1], stop=10)