Skip to content

Commit

Permalink
fix: only apply comp_prec for floating dtypes (#711)
Browse files Browse the repository at this point in the history
Fix #703.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Improved handling of data types during the reshaping process, ensuring
type conversion only occurs for floating-point data.

- **Bug Fixes**
- Enhanced robustness of data processing by preventing unnecessary type
casting for non-floating-point data types.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
  • Loading branch information
njzjz committed Sep 3, 2024
1 parent 6bf41e3 commit c311d16
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 3 additions & 1 deletion dpdata/deepmd/comp.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ def dump(folder, data, set_size=5000, comp_prec=np.float32, remove_sets=True):
f"Shape of {dtype.name} is not (nframes, ...), but {dtype.shape}. This type of data will not converted to deepmd/npy format."
)
continue
ddata = np.reshape(data[dtype.name], [nframes, -1]).astype(comp_prec)
ddata = np.reshape(data[dtype.name], [nframes, -1])
if np.issubdtype(ddata.dtype, np.floating):
ddata = ddata.astype(comp_prec)
for ii in range(nsets):
set_stt = ii * set_size
set_end = (ii + 1) * set_size
Expand Down
7 changes: 4 additions & 3 deletions dpdata/deepmd/hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,10 @@ def dump(
for dt, prop in data_types.items():
if dt in data:
if prop["dump"]:
reshaped_data[dt] = np.reshape(data[dt], prop["shape"]).astype(
comp_prec
)
ddata = np.reshape(data[dt], prop["shape"])
if np.issubdtype(ddata.dtype, np.floating):
ddata = ddata.astype(comp_prec)
reshaped_data[dt] = ddata

# dump frame properties: cell, coord, energy, force and virial
nsets = nframes // set_size
Expand Down

0 comments on commit c311d16

Please sign in to comment.