pyerrors/tests/roots_test.py

45 lines
1,015 B
Python
Raw Normal View History

2021-10-15 12:56:07 +01:00
import numpy as np
import pyerrors as pe
import pytest
2021-10-15 13:05:00 +01:00
np.random.seed(0)
2021-10-15 14:13:06 +01:00
2021-10-15 13:05:00 +01:00
def test_root_linear():
2021-10-15 12:56:07 +01:00
def root_function(x, d):
return x - d
value = np.random.normal(0, 100)
my_obs = pe.pseudo_Obs(value, 0.1, 't')
my_root = pe.roots.find_root(my_obs, root_function)
assert np.isclose(my_root.value, value)
2021-12-04 13:11:19 +00:00
assert np.isclose(my_root.value, my_root.r_values['t'])
2021-10-15 13:05:00 +01:00
difference = my_obs - my_root
assert difference.is_zero()
def test_root_linear_idl():
def root_function(x, d):
return x - d
my_obs = pe.Obs([np.random.rand(50)], ['t'], idl=[range(20, 120, 2)])
my_root = pe.roots.find_root(my_obs, root_function)
difference = my_obs - my_root
assert difference.is_zero()
def test_root_no_autograd():
def root_function(x, d):
return x - np.log(np.exp(d))
value = np.random.normal(0, 100)
my_obs = pe.pseudo_Obs(value, 0.1, 't')
with pytest.raises(Exception):
my_root = pe.roots.find_root(my_obs, root_function)