Skip to content

Commit

Permalink
Fix tensor mapping (#2720)
Browse files Browse the repository at this point in the history
  • Loading branch information
utf committed Nov 7, 2022
1 parent dd884cf commit 511d1ff
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pymatgen/core/tensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1050,8 +1050,8 @@ def __init__(self, tensors: Sequence[Tensor] = (), values: Sequence = (), tol: f
"""
if len(values) != len(tensors):
raise ValueError("TensorMapping must be initialized with tensors and values of equivalent length")
self._tensor_list = tensors
self._value_list = values
self._tensor_list = list(tensors) # needs to be a list
self._value_list = list(values) # needs to be a list
self.tol = tol

def __getitem__(self, item):
Expand Down
6 changes: 5 additions & 1 deletion pymatgen/core/tests/test_tensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,11 @@ def test_tensor_mapping(self):
assert reduced[tkey] == "test_val"
# Test empty initialization
empty = TensorMapping()
assert empty._tensor_list == ()
assert empty._tensor_list == []

# test adding to empty tensor mapping
empty[tkey] = 1
assert empty[tkey] == 1

def test_populate(self):
test_data = loadfn(os.path.join(PymatgenTest.TEST_FILES_DIR, "test_toec_data.json"))
Expand Down

0 comments on commit 511d1ff

Please sign in to comment.