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
95fd7be8
Commit
95fd7be8
authored
3 years ago
by
Matthias Diener
Browse files
Options
Downloads
Patches
Plain Diff
pyopenclac.to_numpy special case isscalar
parent
3e9fd368
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arraycontext/impl/pyopencl.py
+3
-0
3 additions, 0 deletions
arraycontext/impl/pyopencl.py
test/test_arraycontext.py
+9
-13
9 additions, 13 deletions
test/test_arraycontext.py
with
12 additions
and
13 deletions
arraycontext/impl/pyopencl.py
+
3
−
0
View file @
95fd7be8
...
...
@@ -323,6 +323,9 @@ class PyOpenCLArrayContext(ArrayContext):
return
cla
.
to_device
(
self
.
queue
,
array
,
allocator
=
self
.
allocator
)
def
to_numpy
(
self
,
array
):
from
numpy
import
isscalar
if
isscalar
(
array
):
return
array
return
array
.
get
(
queue
=
self
.
queue
)
def
call_loopy
(
self
,
t_unit
,
**
kwargs
):
...
...
This diff is collapsed.
Click to expand it.
test/test_arraycontext.py
+
9
−
13
View file @
95fd7be8
...
...
@@ -401,18 +401,16 @@ def test_dof_array_arithmetic_same_as_numpy(actx_factory):
# {{{ reductions same as numpy
def
test_dof_array_reductions_same_as_numpy
(
actx_factory
):
@pytest.mark.parametrize
(
"
op
"
,
[
"
sum
"
,
"
min
"
,
"
max
"
])
def
test_dof_array_reductions_same_as_numpy
(
actx_factory
,
op
):
actx
=
actx_factory
()
for
name
in
[
"
sum
"
,
"
min
"
,
"
max
"
]:
ary
=
np
.
random
.
randn
(
3000
)
np_red
=
getattr
(
np
,
name
)(
ary
)
actx_red
=
getattr
(
actx
.
np
,
name
)(
actx
.
from_numpy
(
ary
))
if
not
np
.
isscalar
(
actx_red
):
actx_red
=
actx
.
to_numpy
(
actx_red
)
ary
=
np
.
random
.
randn
(
3000
)
np_red
=
getattr
(
np
,
op
)(
ary
)
actx_red
=
getattr
(
actx
.
np
,
op
)(
actx
.
from_numpy
(
ary
))
actx_red
=
actx
.
to_numpy
(
actx_red
)
assert
np
.
allclose
(
np_red
,
actx_red
)
assert
np
.
allclose
(
np_red
,
actx_red
)
# }}}
...
...
@@ -725,8 +723,7 @@ def test_norm_complex(actx_factory, norm_ord):
norm_a_ref
=
np
.
linalg
.
norm
(
a
,
norm_ord
)
norm_a
=
actx
.
np
.
linalg
.
norm
(
actx
.
from_numpy
(
a
),
norm_ord
)
if
not
np
.
isscalar
(
norm_a
):
norm_a
=
actx
.
to_numpy
(
norm_a
)
norm_a
=
actx
.
to_numpy
(
norm_a
)
assert
abs
(
norm_a_ref
-
norm_a
)
/
norm_a
<
1e-13
...
...
@@ -745,8 +742,7 @@ def test_norm_ord_none(actx_factory, ndim):
norm_a_ref
=
np
.
linalg
.
norm
(
a
,
ord
=
None
)
norm_a
=
actx
.
np
.
linalg
.
norm
(
actx
.
from_numpy
(
a
),
ord
=
None
)
if
not
np
.
isscalar
(
norm_a
):
norm_a
=
actx
.
to_numpy
(
norm_a
)
norm_a
=
actx
.
to_numpy
(
norm_a
)
np
.
testing
.
assert_allclose
(
norm_a
,
norm_a_ref
)
...
...
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