Skip to content

Commit

Permalink
simplify implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielYang59 committed Nov 22, 2024
1 parent 65902f4 commit f2c3252
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/pymatgen/util/num.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@ def make_symmetric_matrix_from_upper_tri(val: ArrayLike) -> NDArray:
if (array := np.asarray(val)).shape != (6,):
raise ValueError(f"Expect val of length 6, got {array.shape}")

idx = [0, 3, 4, 1, 5, 2]
array = array[idx]
mask = ~np.tri(3, k=-1, dtype=bool)
out = np.zeros((3, 3), dtype=array.dtype)
out[mask] = array

out.T[mask] = array
return out
return np.array(
[
[array[0], array[3], array[4]],
[array[3], array[1], array[5]],
[array[4], array[5], array[2]],
]
)

0 comments on commit f2c3252

Please sign in to comment.