Skip to content

Commit

Permalink
TN: fix unintended mutation when updating parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmgray committed Jul 10, 2024
1 parent ae6266b commit 8d3c6de
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions quimb/tensor/tensor_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1408,12 +1408,19 @@ def set_params(self, params):
data array. This is mainly for providing an interface for 'structured'
arrays e.g. with block sparsity to interact with optimization.
"""
if hasattr(self.data, "set_params"):
self.data.set_params(params)
elif hasattr(self.data, "params"):
self.data.params = params
data = self.data
if hasattr(data, "set_params"):
# Tensor don't modify their data inplace
data = data.copy()
data.set_params(params)
elif hasattr(data, "params"):
# Tensor don't modify their data inplace
data = data.copy()
data.params = params
else:
self._set_data(params)
data = params

self._set_data(data)

def copy(self, deep=False, virtual=False):
"""Copy this tensor.
Expand Down

0 comments on commit 8d3c6de

Please sign in to comment.