Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
arraycontext
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
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
Alexandru Fikl
arraycontext
Commits
286011de
Commit
286011de
authored
3 years ago
by
Kaushik Kulkarni
Browse files
Options
Downloads
Patches
Plain Diff
adds test_actx_compile
parent
666be4a4
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/test_arraycontext.py
+34
-0
34 additions, 0 deletions
test/test_arraycontext.py
with
34 additions
and
0 deletions
test/test_arraycontext.py
+
34
−
0
View file @
286011de
...
...
@@ -754,6 +754,40 @@ def test_norm_ord_none(actx_factory, ndim):
np
.
testing
.
assert_allclose
(
norm_a
,
norm_a_ref
)
# {{{ test_actx_compile helpers
@with_container_arithmetic
(
bcast_obj_array
=
True
,
rel_comparison
=
True
)
@dataclass_array_container
@dataclass
(
frozen
=
True
)
class
Velocity2D
:
u
:
np
.
ndarray
v
:
np
.
ndarray
def
scale_and_to_speed
(
alpha
,
vel
):
actx
=
vel
.
array_context
scaled_vel
=
alpha
*
vel
return
actx
.
np
.
sqrt
(
scaled_vel
.
u
**
2
+
scaled_vel
.
v
**
2
)
# }}}
def
test_actx_compile
(
actx_factory
):
actx
=
actx_factory
()
compiled_rhs
=
actx
.
compile
(
scale_and_to_speed
)
v_x
=
np
.
random
.
rand
(
10
)
v_y
=
np
.
random
.
rand
(
10
)
vel
=
actx
.
from_numpy
(
Velocity2D
(
v_x
,
v_y
))
scaled_speed
=
compiled_rhs
(
3.14
,
vel
)
np
.
testing
.
assert_allclose
(
actx
.
to_numpy
(
scaled_speed
),
3.14
*
np
.
sqrt
(
v_x
**
2
+
v_y
**
2
))
if
__name__
==
"
__main__
"
:
import
sys
if
len
(
sys
.
argv
)
>
1
:
...
...
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