Пример #1
0
def test_interp_negative(array):
    result = 0.5 + torch_interp(array, [0.0, 0.5, 1.0], [-2.0, 0.0, 2.0]) / 4.0
    assert pytest.approx(0.0, abs=1e-6) == torch.mean(array - result)
Пример #2
0
def test_interp_multiply(array):
    result = (torch_interp(array, [0.0, 1.0], [2.0, 4.0]) - 2.0) * 0.5
    assert pytest.approx(0.0, abs=1e-6) == torch.mean(array - result)
Пример #3
0
def test_interp_clamp(array):
    result = torch_interp(array, [0.2, 0.8], [0.2, 0.8])
    print(array.clamp(0.2, 0.8), result)
    assert pytest.approx(
        0.0, abs=1e-6) == torch.mean(array.clamp(0.2, 0.8) - result)
Пример #4
0
def test_interp_offset(array):
    result = torch_interp(array, [0.0, 1.0], [2.0, 3.0]) - 2.0
    assert pytest.approx(0.0, abs=1e-6) == torch.mean(array - result)
Пример #5
0
def test_interp_inverse(array):
    result = 1.0 - torch_interp(array, [0.0, 0.75, 1.0], [1.0, 0.25, 0.0])
    assert pytest.approx(0.0, abs=1e-6) == torch.mean(array - result)
Пример #6
0
def test_interp_nonlinear_intervals(array):
    result = torch_interp(array, [0.0, 0.1, 0.8, 1.0], [0.0, 0.1, 0.8, 1.0])
    assert pytest.approx(0.0, abs=1e-6) == torch.mean(array - result)
Пример #7
0
def test_interp_linear_extrapolate(array):
    result = torch_interp(array, [-1.0, 2.0], [-1.0, 2.0])
    assert pytest.approx(0.0, abs=1e-6) == torch.mean(array - result)
Пример #8
0
def test_interp_linear_unit(array):
    result = torch_interp(array, [0.0, 0.5, 1.0], [0.0, 0.5, 1.0])
    assert (array == result).all()