Skip to content

Commit f537d07

Browse files
documented compiled POD
1 parent 881c7ea commit f537d07

File tree

1 file changed

+31
-30
lines changed

1 file changed

+31
-30
lines changed

Diff for: pyLOM/POD/wrapper.pyx

+31-30
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,19 @@ def _drun(double[:,:] X, int remove_mean, int randomized, int r, int q, int seed
135135
@cython.nonecheck(False)
136136
@cython.cdivision(True) # turn off zero division check
137137
def run(real[:,:] X, int remove_mean=True, int randomized=False, const int r=1, const int q=3, const int seed=-1):
138-
'''
139-
Run POD analysis of a matrix X.
138+
r'''
139+
Run POD analysis of a matrix.
140140
141-
Inputs:
142-
- X[ndims*nmesh,n_temp_snapshots]: data matrix
143-
- remove_mean: whether or not to remove the mean flow
141+
Args:
142+
X (np.ndarray): data matrix of size [ndims*nmesh,n_temp_snapshots].
143+
remove_mean (bool, optional): whether or not to remove the mean flow (default: ``True``).
144+
randomized (bool, optional): whether to perform randomized POD or not (default: ``False``).
145+
r (int, optional): in case of performing randomized POD, how many modes do we want to recover. This option has no effect when randomized=False (default: ``1``).
146+
q (int, optional): in case of performing randomized POD, how many power iterations are performed. This option has no effect when randomized=False (default: ``3``).
147+
seed (int, optional): seed for reproducibility of randomized operations. This option has no effect when randomized=False (default: ``-1``).
144148
145149
Returns:
146-
- U: are the POD modes.
147-
- S: are the singular values.
148-
- V: are the right singular vectors.
150+
[(np.ndarray), (np.ndarray), (np.ndarray)]: POD spatial modes (left singular vectors), singular values and temporal coefficients (right singular vectors).
149151
'''
150152
seed = <int>time(NULL) if seed < 0 else seed
151153
if real is double:
@@ -234,23 +236,22 @@ def _dtruncate(double[:,:] U, double[:] S, double[:,:] V, double r):
234236
@cython.nonecheck(False)
235237
@cython.cdivision(True) # turn off zero division check
236238
def truncate(real[:,:] U, real[:] S, real[:,:] V, real r=1e-8):
237-
'''
238-
Truncate POD matrices (U,S,V) given a residual r.
239-
240-
Inputs:
241-
- U(m,n) are the POD modes.
242-
- S(n) are the singular values.
243-
- V(n,n) are the right singular vectors.
244-
- r target residual, number of modes, or cumulative energy threshold.
245-
* If r >= 1, it is treated as the number of modes.
246-
* If r < 1 and r > 0 it is treated as the residual target.
247-
* If r < 1 and r < 0 it is treated as the fraction of cumulative energy to retain.
248-
Note: must be in (0,-1] and r = -1 is valid
239+
r'''
240+
Truncate POD matrices (U, S, V) given a residual, number of modes or cumulative energy r.
241+
242+
Args:
243+
U (np.ndarray): of size (m,n), are the POD modes.
244+
S (np.ndarray): of size (n), are the singular values.
245+
V (np.ndarray): of size (n,n), are the right singular vectors.
246+
r (float, optional) target residual, number of modes, or cumulative energy threshold (default: ``1e-8``).
247+
* If r >= 1, it is treated as the number of modes.
248+
* If r < 1 and r > 0 it is treated as the residual target.
249+
* If r < 1 and r < 0 it is treated as the fraction of cumulative energy to retain.
250+
Note: must be in (0,-1] and r = -1 is valid
249251
250252
Returns:
251-
- U(m,N) are the POD modes (truncated at N).
252-
- S(N) are the singular values (truncated at N).
253-
- V(N,n) are the right singular vectors (truncated at N).
253+
[(np.array), (np.array), (np.array)]: Truncated POD spatial modes (left singular vectors), singular values and temporal coefficients (right singular vectors).
254+
254255
'''
255256
if real is double:
256257
return _dtruncate(U,S,V,r)
@@ -334,19 +335,19 @@ def _dreconstruct(double[:,:] U, double[:] S, double[:,:] V):
334335
@cython.nonecheck(False)
335336
@cython.cdivision(True) # turn off zero division check
336337
def reconstruct(real[:,:] U, real[:] S, real[:,:] V):
337-
'''
338+
r'''
338339
Reconstruct the flow given the POD decomposition matrices
339340
that can be possibly truncated.
340341
N is the truncated size
341342
n is the number of snapshots
342343
343-
Inputs:
344-
- U(m,N) are the POD modes.
345-
- S(N) are the singular values.
346-
- V(N,n) are the right singular vectors.
344+
Args:
345+
U (np.ndarray): of size (m,n), are the POD modes.
346+
S (np.ndarray): of size (n), are the singular values.
347+
V (np.ndarray): of size (n,n), are the right singular vectors.
347348
348-
Outputs
349-
- X(m,n) is the reconstructed flow.
349+
Returns:
350+
(np.array): Reconstructed flow.
350351
'''
351352
if real is double:
352353
return _dreconstruct(U,S,V)

0 commit comments

Comments
 (0)