Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
LISA Instrument
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LISA Simulation
LISA Instrument
Commits
3c9a4fc8
Commit
3c9a4fc8
authored
3 months ago
by
Wolfgang Kastaun
Browse files
Options
Downloads
Patches
Plain Diff
added some unit tests for fixed shift with numpy or dask
parent
8348c5ab
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/test_fixed_shift_dask.py
+88
-0
88 additions, 0 deletions
tests/test_fixed_shift_dask.py
tests/test_fixed_shift_numpy.py
+63
-0
63 additions, 0 deletions
tests/test_fixed_shift_numpy.py
with
151 additions
and
0 deletions
tests/test_fixed_shift_dask.py
0 → 100644
+
88
−
0
View file @
3c9a4fc8
import
numpy
as
np
import
pytest
from
lisainstrument.dynamic_delay_numpy
import
DynShiftBC
from
lisainstrument.dynamic_delay_dask
import
numpyfy_dask_multi
from
lisainstrument.fixed_shift_numpy
import
make_fixed_shift_lagrange_numpy
from
lisainstrument.fixed_shift_dask
import
make_fixed_shift_lagrange_dask
def
test_fixed_shift_lagrange_dask
()
->
None
:
order
=
5
length
=
order
+
1
t
,
dt
=
np
.
linspace
(
-
5.345
,
10.345
,
1003
,
retstep
=
True
)
def
g
(
x
):
return
(
4.32546
+
3.34324
*
x
-
4.342
*
x
**
2
-
0.46
*
x
**
3
+
1.43598
*
x
**
4
-
np
.
pi
*
x
**
5
)
y
=
g
(
t
)
for
d
in
(
0.93456456
/
dt
,
3.1
,
3.5
,
3.9
,
4.0
,
4.1
,
4.5
,
4.9
,
116.0
):
op_np
=
make_fixed_shift_lagrange_numpy
(
DynShiftBC
.
FLAT
,
DynShiftBC
.
EXCEPTION
,
length
)
op_da
=
make_fixed_shift_lagrange_dask
(
DynShiftBC
.
FLAT
,
DynShiftBC
.
EXCEPTION
,
length
)
op_na
=
numpyfy_dask_multi
(
op_da
,
chunks
=
113
)
s_np
=
op_np
(
y
,
d
)
s_na
=
op_na
(
y
,
d
)
s_ex
=
g
(
t
-
d
*
dt
)
margin_ex
=
-
int
(
np
.
floor
(
-
d
))
+
order
//
2
assert
s_na
==
pytest
.
approx
(
s_np
,
rel
=
1e-14
,
abs
=
0
)
assert
s_ex
[
margin_ex
:]
==
pytest
.
approx
(
s_na
[
margin_ex
:],
abs
=
1e-15
,
rel
=
5e-13
)
with
pytest
.
raises
(
RuntimeError
):
op_na
(
y
,
-
d
)
op2_np
=
make_fixed_shift_lagrange_numpy
(
DynShiftBC
.
EXCEPTION
,
DynShiftBC
.
FLAT
,
length
)
op2_da
=
make_fixed_shift_lagrange_dask
(
DynShiftBC
.
EXCEPTION
,
DynShiftBC
.
FLAT
,
length
)
op2_na
=
numpyfy_dask_multi
(
op2_da
,
chunks
=
113
)
s2_np
=
op2_np
(
y
,
-
d
)
s2_na
=
op2_na
(
y
,
-
d
)
s2_ex
=
g
(
t
+
d
*
dt
)
margin2_ex
=
int
(
np
.
floor
(
d
))
+
(
length
-
1
-
order
//
2
)
assert
s2_na
==
pytest
.
approx
(
s2_np
,
rel
=
1e-14
,
abs
=
0
)
assert
s2_ex
[:
-
margin2_ex
]
==
pytest
.
approx
(
s2_na
[:
-
margin2_ex
],
abs
=
1e-15
,
rel
=
5e-13
)
with
pytest
.
raises
(
RuntimeError
):
op2_na
(
y
,
d
)
op3_da
=
make_fixed_shift_lagrange_dask
(
DynShiftBC
.
FLAT
,
DynShiftBC
.
FLAT
,
length
)
op3_na
=
numpyfy_dask_multi
(
op3_da
,
chunks
=
113
)
s3_na
=
op3_na
(
y
,
d
)
assert
s3_na
==
pytest
.
approx
(
s_np
,
rel
=
1e-14
,
abs
=
0
)
s4_na
=
op3_na
(
y
,
-
d
)
assert
s4_na
==
pytest
.
approx
(
s2_np
,
rel
=
1e-14
,
abs
=
0
)
This diff is collapsed.
Click to expand it.
tests/test_fixed_shift_numpy.py
0 → 100644
+
63
−
0
View file @
3c9a4fc8
import
numpy
as
np
import
pytest
from
lisainstrument.dynamic_delay_numpy
import
DynShiftBC
from
lisainstrument.fixed_shift_numpy
import
make_fixed_shift_lagrange_numpy
def
test_fixed_shift_lagrange_dask
()
->
None
:
order
=
5
length
=
order
+
1
t
,
dt
=
np
.
linspace
(
-
5.345
,
10.345
,
1003
,
retstep
=
True
)
def
g
(
x
):
return
(
4.32546
+
3.34324
*
x
-
4.342
*
x
**
2
-
0.46
*
x
**
3
+
1.43598
*
x
**
4
-
3.3456
*
x
**
5
)
y
=
g
(
t
)
for
d
in
(
0.93456456
/
dt
,
3.1
,
3.5
,
3.9
,
4.0
,
4.1
,
4.5
,
4.9
):
# ~ d = 0.93456456 / dt
op_np
=
make_fixed_shift_lagrange_numpy
(
DynShiftBC
.
FLAT
,
DynShiftBC
.
EXCEPTION
,
length
)
s_np
=
op_np
(
y
,
d
)
s_ex
=
g
(
t
-
d
*
dt
)
margin_ex
=
-
int
(
np
.
floor
(
-
d
))
+
order
//
2
print
(
d
,
d
*
dt
,
margin_ex
)
assert
s_ex
[
margin_ex
:]
==
pytest
.
approx
(
s_np
[
margin_ex
:],
abs
=
1e-15
,
rel
=
5e-13
)
# ~ assert np.min(np.abs(s_ex[:margin_ex] - s_np[:margin_ex])) > np.max(np.abs(y[:margin_ex]))*1e-10
with
pytest
.
raises
(
RuntimeError
):
op_np
(
y
,
-
d
)
op2_np
=
make_fixed_shift_lagrange_numpy
(
DynShiftBC
.
EXCEPTION
,
DynShiftBC
.
FLAT
,
length
)
s2_np
=
op2_np
(
y
,
-
d
)
s2_ex
=
g
(
t
+
d
*
dt
)
margin2_ex
=
int
(
np
.
floor
(
d
))
+
(
length
-
1
-
order
//
2
)
assert
s2_ex
[:
-
margin2_ex
]
==
pytest
.
approx
(
s2_np
[:
-
margin2_ex
],
abs
=
1e-15
,
rel
=
5e-13
)
# ~ assert np.min(np.abs(s2_ex[-margin2_ex:] - s2_np[-margin2_ex:])) > np.max(np.abs(y[-margin2_ex:]))*1e-10
with
pytest
.
raises
(
RuntimeError
):
op2_np
(
y
,
d
)
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