added synced parameters

This commit is contained in:
Benoît Sierro
2023-10-18 08:52:31 +02:00
parent 0e1eb502a4
commit c153ef3af9
3 changed files with 261 additions and 199 deletions

View File

@@ -102,6 +102,53 @@ def test_constant_list():
conf.y(6)
def test_simple_synchronize():
"""synchronize 2 variable fields"""
@vdataclass
class Conf:
x: Variable = vfield(default=[1, 2, 7])
y: Variable = vfield(default=[2, 0, 0], sync=x)
conf = Conf()
assert conf.x(0) == 1
assert conf.x(1) == 2
assert conf.x(2) == 7
assert conf.y(0) == 2
assert conf.y(1) == 0
assert conf.y(2) == 0
with pytest.raises(ValueError):
conf.y(3)
with pytest.raises(ValueError):
conf.x(3)
def test_sync_strict():
@vdataclass
class Conf:
x: Variable = vfield(default=[1, 2, 7])
y: Variable = vfield(default=[2, 0], sync=x)
conf = Conf()
assert conf.x(2) == 7
with pytest.raises(ValueError):
conf.y(0)
conf.x = [78, 55]
assert len(conf) == 2
assert conf.y(1) == 0
assert conf.x(1) == 55
with pytest.raises(ValueError):
conf.y = [1, 2, 3]
conf.x = [11, 22, 33, 44, 55]
conf.y = [0, 1, 33, 111, 1111]
assert conf.x(2) == conf.y(2) == 33
assert len(conf) == len(conf.x) == len(conf.y) == 5
def test_decoration():
"""proper construction of the class"""
@@ -275,15 +322,3 @@ def test_filter():
mat = np.random.rand(70, 12, 11)
assert f(mat.reshape(len(conf), 11), squeeze=False).shape == (12, 1, 1, 3, 11)
def test_param_parsing():
"""parsing a string or path returns the correct values"""
def test_config_parsing():
"""parsing a string returns the exact id corresponding to the string/path"""
def test_repr():
"""print a config object correctly"""