示例#1
0
def test_interp1d_6():
    with pytest.raises(ValueError):
        x = 2.0
        y1 = x1 = 0.0
        y2 = x2 = 1.0
        x3 = 2.0
        interp1d(x, [x1, x2, x3], [y1, y2])
示例#2
0
def test_interp1d_9():
    x = 0.25
    xp = [0.1, 0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0]
    yp = [2.0 * _ for _ in xp]
    value = interp1d(x, xp, yp)
    assert value == x * 2.0
示例#3
0
def test_interp1d_1():
    x = 0.5
    y1 = x1 = 0.0
    y2 = x2 = 1.0
    value = interp1d(x, [x1, x2], [y1, y2])
    assert value == y1 + ((x - x1) / (x2 - x1)) * (y2 - y1)
示例#4
0
def test_interp1d_5():
    with pytest.raises(ValueError):
        x = 2.0
        x1 = 0.0
        y2 = x2 = 1.0
        interp1d(x, [x1, x2], [y2])
示例#5
0
def test_interp1d_4():
    with pytest.raises(ValueError):
        x = 2.0
        y1 = x1 = 0.0
        y2 = 1.0
        interp1d(x, [x1], [y1, y2])
示例#6
0
def test_interp1d_2():
    with pytest.raises(ValueError):
        x = -1.0
        y1 = x1 = 0.0
        y2 = x2 = 1.0
        interp1d(x, [x1, x2], [y1, y2])
示例#7
0
for kk in range(2, 5):
    x1 = 0
    x2 = int(10**kk)
    size.append(x2)

    xp = [float(_) for _ in range(x1, x2 + 1)]
    yp = [_**3.0 for _ in xp]

    x = [random.uniform(float(x1), float(x2)) for _ in range(10000)]

    start_time = time.time()
    v_1 = [interp(_, xp, yp) for _ in x]
    time_1 = time.time() - start_time

    start_time = time.time()
    v_2 = [interp1d(_, xp, yp) for _ in x]
    time_2 = time.time() - start_time

    times.append([time_1, time_2])
    ratios.append(time_1 / time_2)
    deltas.append(sum(_[1] - _[0] for _ in zip(v_1, v_2)))

# Print benchmark ratios
print('--- Benchmark results ---')
print('List size : Ratio')
for r, v in zip(size, ratios):
    print('    %i : %f' % (r, v))
print('Check convergence. Difference between interp and interp1d = %f' %
      max(deltas))