Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tensor mapping #2720

Merged
merged 1 commit into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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