Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
grudge
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
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
Andreas Klöckner
grudge
Commits
214e865b
Commit
214e865b
authored
3 years ago
by
Matt Smith
Browse files
Options
Downloads
Patches
Plain Diff
attempt to fix force_device_scalars handling
parent
dbcec037
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
grudge/reductions.py
+11
-14
11 additions, 14 deletions
grudge/reductions.py
with
11 additions
and
14 deletions
grudge/reductions.py
+
11
−
14
View file @
214e865b
...
...
@@ -165,18 +165,7 @@ def nodal_sum_loc(dcoll: DiscretizationCollection, dd, vec) -> Any:
actx
=
vec
.
array_context
if
hasattr
(
actx
,
"
_force_device_scalars
"
):
force_device_scalars
=
actx
.
_force_device_scalars
else
:
force_device_scalars
=
True
def
device_sum
(
x
):
result
=
actx
.
np
.
sum
(
x
)
if
not
force_device_scalars
:
result
=
actx
.
from_numpy
(
np
.
array
(
result
))
return
result
return
sum
([
device_sum
(
grp_ary
)
for
grp_ary
in
vec
])
return
sum
([
actx
.
np
.
sum
(
grp_ary
)
for
grp_ary
in
vec
])
def
nodal_min
(
dcoll
:
DiscretizationCollection
,
dd
,
vec
)
->
Any
:
...
...
@@ -228,9 +217,13 @@ def nodal_min_loc(dcoll: DiscretizationCollection, dd, vec) -> Any:
result
=
as_device_scalar
(
result
)
return
result
re
turn
reduce
(
re
sult
=
reduce
(
lambda
acc
,
grp_ary
:
actx
.
np
.
minimum
(
acc
,
device_min
(
grp_ary
)),
vec
,
as_device_scalar
(
np
.
inf
))
if
not
force_device_scalars
:
result
=
actx
.
to_numpy
(
result
)[()]
return
result
def
nodal_max
(
dcoll
:
DiscretizationCollection
,
dd
,
vec
)
->
Any
:
...
...
@@ -282,9 +275,13 @@ def nodal_max_loc(dcoll: DiscretizationCollection, dd, vec) -> Any:
result
=
as_device_scalar
(
result
)
return
result
re
turn
reduce
(
re
sult
=
reduce
(
lambda
acc
,
grp_ary
:
actx
.
np
.
maximum
(
acc
,
device_max
(
grp_ary
)),
vec
,
as_device_scalar
(
-
np
.
inf
))
if
not
force_device_scalars
:
result
=
actx
.
to_numpy
(
result
)[()]
return
result
def
integral
(
dcoll
:
DiscretizationCollection
,
dd
,
vec
):
...
...
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