Skip to content

Commit e6b5203

Browse files
committed
Reformatting to pacify pylint
1 parent ba61fd1 commit e6b5203

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

pydmd/utils.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import warnings
44
from numbers import Number
5-
from typing import Tuple
6-
5+
from typing import NamedTuple
6+
from collections import namedtuple
77
import numpy as np
88
from numpy.lib.stride_tricks import sliding_window_view
99

@@ -110,7 +110,9 @@ def compute_rank(X: np.ndarray, svd_rank: Number = 0) -> int:
110110

111111
def compute_tlsq(
112112
X: np.ndarray, Y: np.ndarray, tlsq_rank: int
113-
) -> Tuple[np.ndarray, np.ndarray]:
113+
) -> NamedTuple(
114+
"TLSQ", [("X_denoised", np.ndarray), ("Y_denoised", np.ndarray)]
115+
):
114116
"""
115117
Compute Total Least Square.
116118
@@ -124,7 +126,8 @@ def compute_tlsq(
124126
method.
125127
:type tlsq_rank: int
126128
:return: the denoised matrix X, the denoised matrix Y
127-
:rtype: Tuple[np.ndarray, np.ndarray]
129+
:rtype: NamedTuple("TLSQ", [('X_denoised', np.ndarray),
130+
('Y_denoised', np.ndarray)])
128131
129132
References:
130133
https://arxiv.org/pdf/1703.11004.pdf
@@ -137,13 +140,15 @@ def compute_tlsq(
137140
V = np.linalg.svd(np.append(X, Y, axis=0), full_matrices=False)[-1]
138141
rank = min(tlsq_rank, V.shape[0])
139142
VV = V[:rank, :].conj().T.dot(V[:rank, :])
140-
141-
return X.dot(VV), Y.dot(VV)
143+
TLSQ = namedtuple("TLSQ", ["X_denoised", "Y_denoised"])
144+
return TLSQ(X.dot(VV), Y.dot(VV))
142145

143146

144147
def compute_svd(
145148
X: np.ndarray, svd_rank: Number = 0
146-
) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:
149+
) -> NamedTuple(
150+
"SVD", [("U", np.ndarray), ("s", np.ndarray), ("V", np.ndarray)]
151+
):
147152
"""
148153
Truncated Singular Value Decomposition.
149154
@@ -158,7 +163,9 @@ def compute_svd(
158163
:type svd_rank: int or float
159164
:return: the truncated left-singular vectors matrix, the truncated
160165
singular values array, the truncated right-singular vectors matrix.
161-
:rtype: Tuple[np.ndarray, np.ndarray, np.ndarray]
166+
:rtype: NamedTuple("SVD", [('U', np.ndarray),
167+
('s', np.ndarray),
168+
('V', np.ndarray)])
162169
163170
References:
164171
Gavish, Matan, and David L. Donoho, The optimal hard threshold for
@@ -172,8 +179,9 @@ def compute_svd(
172179
U = U[:, :rank]
173180
V = V[:, :rank]
174181
s = s[:rank]
182+
SVD = namedtuple("SVD", ["U", "s", "V"])
175183

176-
return U, s, V
184+
return SVD(U, s, V)
177185

178186

179187
def pseudo_hankel_matrix(X: np.ndarray, d: int) -> np.ndarray:

0 commit comments

Comments
 (0)