Exemple #1
0
def test_ols_2d():
    """Test the 2D case, where the scipy_regression function needs to loop
    and the ols.fit() function should deliver a significant speed-up.

    """
    # Check both give the same results
    xdata, ydata = testdata.generate_2d()
    reference = scipy_regression(xdata, ydata)
    output = ols.fit(xdata, ydata)
    assert np.isclose(reference, output).all()

    # Check speed-up
    wrapped_reference = wrapper(scipy_regression, xdata, ydata)
    time_reference = timeit.timeit(wrapped_reference, number=5)
    wrapped_output = wrapper(ols.fit, xdata, ydata)
    time_output = timeit.timeit(wrapped_output, number=5)
    assert time_output < time_reference
    speedup = time_reference / time_output
    print 'Fractional speedup: {:.0f}.0'.format(speedup)
Exemple #2
0
def test_ols_1d():
    """Test the 1D case, where no looping is required."""
    xdata, ydata = testdata.generate_1d()
    reference = scipy_regression(xdata, ydata)
    output = ols.fit(xdata, ydata)
    assert np.isclose(reference, output).all()