Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
modepy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Xiaoyu Wei
modepy
Commits
090683e4
Commit
090683e4
authored
9 years ago
by
Andreas Klöckner
Browse files
Options
Downloads
Patches
Plain Diff
Placate PEP8
parent
760f54fc
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/test_tools.py
+20
-25
20 additions, 25 deletions
test/test_tools.py
with
20 additions
and
25 deletions
test/test_tools.py
+
20
−
25
View file @
090683e4
...
...
@@ -24,8 +24,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""
import
numpy
as
np
import
numpy.linalg
as
la
import
modepy
as
mp
...
...
@@ -34,55 +32,58 @@ from functools import partial
import
pytest
# {{{ modal decay test functions
def
jump
(
where
,
x
):
result
=
np
.
empty_like
(
x
)
result
[
x
>=
where
]
=
1
result
[
x
<
where
]
=
0
result
[
x
>=
where
]
=
1
result
[
x
<
where
]
=
0
return
result
def
smooth_jump
(
where
,
x
):
return
np
.
arctan
(
100
*
(
x
-
where
))
/
(
0.5
*
np
.
pi
)
def
kink
(
where
,
x
):
result
=
np
.
empty_like
(
x
)
result
[
x
>=
where
]
=
x
[
x
>=
where
]
result
[
x
<
where
]
=
0
result
[
x
>=
where
]
=
x
[
x
>=
where
]
result
[
x
<
where
]
=
0
return
result
def
c1
(
where
,
x
):
result
=
np
.
empty_like
(
x
)
result
[
x
>=
where
]
=
x
[
x
>=
where
]
**
2
result
[
x
<
where
]
=
0
result
[
x
>=
where
]
=
x
[
x
>=
where
]
**
2
result
[
x
<
where
]
=
0
return
result
def
sample_polynomial
(
x
):
return
3
*
x
**
2
+
5
*
x
+
3
def
constant
(
x
):
return
5
+
0
*
x
# }}}
@pytest.mark.parametrize
((
"
case_name
"
,
"
test_func
"
,
"
dims
"
,
"
n
"
,
"
expected_expn
"
),
[
(
"
jump-1d
"
,
partial
(
jump
,
0
),
1
,
10
,
-
1
),
(
"
kink-1d
"
,
partial
(
kink
,
0
),
1
,
10
,
-
1.7
),
# Slightly off from -2 (same in paper)
(
"
kink-1d
"
,
partial
(
kink
,
0
),
1
,
10
,
-
1.7
),
# Slightly off from -2 (same in paper)
# noqa
(
"
c1-1d
"
,
partial
(
c1
,
0
),
1
,
10
,
-
3
),
# Offset 1D tests
(
"
offset-jump-1d
"
,
partial
(
jump
,
0.8
),
1
,
20
,
-
0.7
),
(
"
offset-kink-1d
"
,
partial
(
kink
,
0.8
),
1
,
20
,
-
0.7
),
# boo
(
"
offset-c1-1d
"
,
partial
(
c1
,
0.8
),
1
,
20
,
-
0.8
),
# boo
(
"
offset-kink-1d
"
,
partial
(
kink
,
0.8
),
1
,
20
,
-
0.7
),
# boo
(
"
offset-c1-1d
"
,
partial
(
c1
,
0.8
),
1
,
20
,
-
0.8
),
# boo
# 2D tests
# A harsh jump introduces high-frequency wiggles transverse to the jump edge.
# Therefore, use a smooth one.
(
"
jump-2d
"
,
partial
(
smooth_jump
,
-
0.1
),
2
,
15
,
-
1.1
),
(
"
kink-2d
"
,
partial
(
kink
,
0
),
2
,
15
,
-
1.6
),
(
"
kink-2d
"
,
partial
(
kink
,
0
),
2
,
15
,
-
1.6
),
(
"
c1-2d
"
,
partial
(
c1
,
-
0.1
),
2
,
15
,
-
2.3
),
])
def
test_modal_decay
(
case_name
,
test_func
,
dims
,
n
,
expected_expn
):
...
...
@@ -106,8 +107,6 @@ def test_modal_decay(case_name, test_func, dims, n, expected_expn):
assert
abs
(
expn
-
expected_expn
)
<
0.1
@pytest.mark.parametrize
((
"
case_name
"
,
"
test_func
"
,
"
dims
"
,
"
n
"
),
[
(
"
sin-1d
"
,
np
.
sin
,
1
,
5
),
(
"
poly-1d
"
,
sample_polynomial
,
1
,
5
),
...
...
@@ -127,7 +126,8 @@ def test_residual_estimation(case_name, test_func, dims, n):
coeffs
=
la
.
solve
(
vdm
,
f
)
from
modepy.modal_decay
import
estimate_relative_expansion_residual
return
estimate_relative_expansion_residual
(
coeffs
.
reshape
(
1
,
-
1
),
dims
,
inner_n
)
return
estimate_relative_expansion_residual
(
coeffs
.
reshape
(
1
,
-
1
),
dims
,
inner_n
)
resid
=
estimate_resid
(
n
)
resid2
=
estimate_resid
(
2
*
n
)
...
...
@@ -135,8 +135,6 @@ def test_residual_estimation(case_name, test_func, dims, n):
assert
resid2
<
resid
@pytest.mark.parametrize
(
"
dims
"
,
[
1
,
2
,
3
])
def
test_resampling_matrix
(
dims
):
ncoarse
=
5
...
...
@@ -155,15 +153,14 @@ def test_resampling_matrix(dims):
assert
la
.
norm
(
my_eye
-
np
.
eye
(
len
(
my_eye
)))
<
4e-13
my_eye_least_squares
=
np
.
dot
(
mp
.
resampling_matrix
(
coarse_basis
,
coarse_nodes
,
fine_nodes
,
least_squares_ok
=
True
),
mp
.
resampling_matrix
(
coarse_basis
,
coarse_nodes
,
fine_nodes
,
least_squares_ok
=
True
),
mp
.
resampling_matrix
(
coarse_basis
,
fine_nodes
,
coarse_nodes
),
)
assert
la
.
norm
(
my_eye_least_squares
-
np
.
eye
(
len
(
my_eye_least_squares
)))
<
1e-13
@pytest.mark.parametrize
(
"
dims
"
,
[
1
,
2
,
3
])
def
test_diff_matrix
(
dims
):
n
=
5
...
...
@@ -184,8 +181,6 @@ def test_diff_matrix(dims):
assert
la
.
norm
(
df_dx
-
df_dx_num
)
<
1e-3
# You can test individual routines by typing
# $ python test_tools.py 'test_routine()'
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment