Skip to content

Commit 21b4c06

Browse files
committed
fix: validate last_dim in EnvMatStatSe for radial-only and full descriptor
1 parent 4c62a26 commit 21b4c06

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

deepmd/dpmodel/utils/env_mat_stat.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ def iter(
9696
dict[str, StatItem]
9797
The statistics of the environment matrix.
9898
"""
99+
if self.last_dim == 4:
100+
radial_only = False
101+
elif self.last_dim == 1:
102+
radial_only = True
103+
else:
104+
raise ValueError(
105+
"last_dim should be 1 for raial-only or 4 for full descriptor."
106+
)
99107
if len(data) == 0:
100108
# workaround to fix IndexError: list index out of range
101109
yield from ()
@@ -119,14 +127,6 @@ def iter(
119127
dtype=get_xp_precision(xp, "global"),
120128
device=array_api_compat.device(data[0]["coord"]),
121129
)
122-
if self.last_dim == 4:
123-
radial_only = False
124-
elif self.last_dim == 1:
125-
radial_only = True
126-
else:
127-
raise ValueError(
128-
"last_dim should be 1 for raial-only or 4 for full descriptor."
129-
)
130130
for system in data:
131131
coord, atype, box, natoms = (
132132
system["coord"],

0 commit comments

Comments
 (0)