Commit 10fe309c authored by Philipp Arras's avatar Philipp Arras
Browse files

Remove MultiField.update()

The reason for this is the following. MultiFields behave very similar to
dictionaries except for the fact that dictionaries are mutable and MultiFields
are immutable. Therefore, MultiField.update() needs to return a new object. That
is different to the dictionary.update() functionality and therefore unintuitive.

MultiField.union() can do the exact same thing as update() used to do.
parent 94d60caa
...@@ -66,11 +66,6 @@ class MultiField(object): ...@@ -66,11 +66,6 @@ class MultiField(object):
def to_dict(self): def to_dict(self):
return {key: val for key, val in zip(self._domain.keys(), self._val)} return {key: val for key, val in zip(self._domain.keys(), self._val)}
def update(self, other):
foo = self.to_dict()
foo.update(other.to_dict())
return MultiField.from_dict(foo)
def __getitem__(self, key): def __getitem__(self, key):
return self._val[self._domain.idx[key]] return self._val[self._domain.idx[key]]
......
...@@ -56,19 +56,3 @@ class Test_Functionality(unittest.TestCase): ...@@ -56,19 +56,3 @@ class Test_Functionality(unittest.TestCase):
f1 = op2(ift.full(dom, 1)) f1 = op2(ift.full(dom, 1))
for val in f1.values(): for val in f1.values():
assert_equal((val == 40).all(), True) assert_equal((val == 40).all(), True)
def test_update(self):
dom = ift.RGSpace(10)
f1 = ift.from_random('normal', domain=dom)
f2 = ift.from_random('normal', domain=dom)
f_new = ift.MultiField.from_dict({'dom1': f1, 'dom2': f2})
f3 = ift.from_random('normal', domain=dom)
f4 = ift.from_random('normal', domain=dom)
f5 = ift.from_random('normal', domain=dom)
f_old = ift.MultiField.from_dict({'dom1': f3, 'dom2': f4, 'dom3': f5})
updated = f_old.update(f_new).to_dict()
updated_true = f_old.to_dict()
updated_true.update(f_new.to_dict())
for key, val in updated.items():
assert_equal((val == updated_true[key]).all(), True)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment