Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Jonas Plewinski
pystencils
Commits
6ce27ece
Commit
6ce27ece
authored
Aug 13, 2019
by
Michael Kuron
Browse files
test Philox against known data
parent
63a9140d
Changes
1
Hide whitespace changes
Inline
Side-by-side
pystencils_tests/test_random.py
View file @
6ce27ece
...
...
@@ -4,6 +4,12 @@ import pystencils as ps
from
pystencils.rng
import
PhiloxFourFloats
,
PhiloxTwoDoubles
# curand_Philox4x32_10(make_uint4(124, i, j, 0), make_uint2(0, 0))
philox_reference
=
np
.
array
([[[
3576608082
,
1252663339
,
1987745383
,
348040302
],
[
1032407765
,
970978240
,
2217005168
,
2424826293
]],
[[
2958765206
,
3725192638
,
2623672781
,
1373196132
],
[
850605163
,
1694561295
,
3285694973
,
2799652583
]]])
def
test_philox_double
():
for
target
in
(
'cpu'
,
'gpu'
):
dh
=
ps
.
create_data_handling
((
2
,
2
),
default_ghost_layers
=
0
,
default_target
=
target
)
...
...
@@ -24,6 +30,12 @@ def test_philox_double():
arr
=
dh
.
gather_array
(
'f'
)
assert
np
.
logical_and
(
arr
<=
1.0
,
arr
>=
0
).
all
()
x
=
philox_reference
[:,:,
0
::
2
]
y
=
philox_reference
[:,:,
1
::
2
]
z
=
x
^
y
<<
(
53
-
32
)
double_reference
=
z
*
2.
**-
53
+
2.
**-
54
assert
(
np
.
allclose
(
arr
,
double_reference
,
rtol
=
0
,
atol
=
np
.
finfo
(
np
.
float64
).
eps
))
def
test_philox_float
():
for
target
in
(
'cpu'
,
'gpu'
):
...
...
@@ -41,3 +53,6 @@ def test_philox_float():
dh
.
all_to_cpu
()
arr
=
dh
.
gather_array
(
'f'
)
assert
np
.
logical_and
(
arr
<=
1.0
,
arr
>=
0
).
all
()
float_reference
=
philox_reference
*
2.
**-
32
+
2.
**-
33
assert
(
np
.
allclose
(
arr
,
float_reference
,
rtol
=
0
,
atol
=
np
.
finfo
(
np
.
float32
).
eps
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment