Skip to content

Commit

Permalink
TNOptimizer: warn and cast for precision loss (jax)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmgray committed Dec 5, 2024
1 parent 2e13857 commit 9df4fed
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions quimb/tensor/optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ def pack(self, tree, name="vector"):
for array, info in zip(arrays, self.infos):
if not isinstance(array, np.ndarray):
array = to_numpy(array)

if array.dtype != info.dtype:
warnings.warn(
"dtype mismatch between input parameter and updated "
"values. This can occur e.g. with jax and double "
"precision arrays (in which case consider setting "
'`jax.config.update("jax_enable_x64", True)` at startup '
"or using single precision parameters directly)."
f" For now casting from {array.dtype} to {info.dtype}."
)
array = array.astype(info.dtype)

# flatten
if info.iscomplex:
# view as real array of double the length
Expand Down

0 comments on commit 9df4fed

Please sign in to comment.