Skip to content

Commit 52f922a

Browse files
Bucanero06mtezzele
authored andcommitted
Update bopdmd.py for better memory efficiency
This change request modifies the `_initialize_alpha` function in the dynamic mode decomposition implementation to enhance memory efficiency. The original implementation created a large diagonal matrix `T`, which led to excessive memory consumption for large datasets. **Key Change**: 1. **Avoid Full Matrix Construction**: Replaced the construction of the full diagonal matrix `T` with direct element-wise operations. This approach significantly reduces memory usage. With these change, I can handle larger datasets without encountering memory allocation errors.
1 parent 09e8134 commit 52f922a

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

pydmd/bopdmd.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,15 +1365,10 @@ def _initialize_alpha(self):
13651365
ux1 = ux[:, :-1]
13661366
ux2 = ux[:, 1:]
13671367

1368-
# Define the diagonal matrix T as the following.
1369-
t1 = self._time[:-1]
1370-
t2 = self._time[1:]
1371-
T = np.diag(t2 - t1)
1372-
13731368
# Define the matrices Y and Z as the following and compute the
13741369
# rank-truncated SVD of Y.
13751370
Y = (ux1 + ux2) / 2
1376-
Z = (ux2 - ux1).dot(np.linalg.inv(T))
1371+
Z = (ux2 - ux1) / (self._time[1:] - self._time[:-1]) # Element-wise division by time differences. w/o large T
13771372
U, s, V = compute_svd(Y, self._svd_rank)
13781373
S = np.diag(s)
13791374

0 commit comments

Comments
 (0)