Skip to content

Commit b4195ae

Browse files
sichinagamtezzele
authored andcommitted
Added test suite
1 parent c14689a commit b4195ae

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import numpy as np
2+
from numpy.testing import assert_allclose
3+
4+
from pydmd import DMD, RDMD
5+
from pydmd.preprocessing import randomized_preprocessing
6+
7+
sample_data = np.load("tests/test_datasets/input_sample.npy")
8+
9+
10+
def test_reconstruction():
11+
"""
12+
Test that a pydmd module preprocessed with
13+
randomization produces accurate reconstructions.
14+
"""
15+
pdmd = randomized_preprocessing(DMD(svd_rank=2), svd_rank=2)
16+
pdmd.fit(sample_data)
17+
assert_allclose(pdmd.reconstructed_data, sample_data)
18+
19+
20+
def test_shape():
21+
"""
22+
Test that a pydmd module preprocessed with
23+
randomization stores data with the expected shape.
24+
"""
25+
pdmd = randomized_preprocessing(
26+
DMD(svd_rank=2),
27+
svd_rank=2,
28+
oversampling=10,
29+
)
30+
pdmd.fit(sample_data)
31+
assert pdmd.snapshots.shape == (12, sample_data.shape[-1])
32+
33+
34+
def test_rdmd():
35+
"""
36+
Test that RDMD and DMD with randomization are essentially the same.
37+
"""
38+
rdmd = RDMD(svd_rank=2, oversampling=10, power_iters=2, seed=1234)
39+
rdmd.fit(sample_data)
40+
41+
pdmd = randomized_preprocessing(
42+
DMD(svd_rank=2),
43+
svd_rank=2,
44+
oversampling=10,
45+
power_iters=2,
46+
seed=1234,
47+
)
48+
pdmd.fit(sample_data)
49+
50+
assert_allclose(pdmd.reconstructed_data, rdmd.reconstructed_data)
51+
assert_allclose(np.sort(pdmd.eigs), np.sort(rdmd.eigs))

0 commit comments

Comments
 (0)