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
112ada65
Commit
112ada65
authored
3 years ago
by
Alexandru Fikl
Committed by
Andreas Klöckner
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
add tests for any and all
parent
db1a7d55
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
+28
-0
28 additions, 0 deletions
test/test_arraycontext.py
with
28 additions
and
0 deletions
test/test_arraycontext.py
+
28
−
0
View file @
112ada65
...
@@ -120,6 +120,14 @@ class DOFArray:
...
@@ -120,6 +120,14 @@ class DOFArray:
__array_priority__
=
10
__array_priority__
=
10
def
__bool__
(
self
):
if
len
(
self
)
==
1
and
self
.
data
[
0
].
size
==
1
:
return
bool
(
self
.
data
[
0
])
raise
ValueError
(
"
The truth value of an array with more than one element is
"
"
ambiguous. Use actx.np.any(x) or actx.np.all(x)
"
)
def
__len__
(
self
):
def
__len__
(
self
):
return
len
(
self
.
data
)
return
len
(
self
.
data
)
...
@@ -260,6 +268,8 @@ def assert_close_to_numpy_in_containers(actx, op, args):
...
@@ -260,6 +268,8 @@ def assert_close_to_numpy_in_containers(actx, op, args):
(
"
where
"
,
3
,
np
.
float64
),
(
"
where
"
,
3
,
np
.
float64
),
(
"
min
"
,
1
,
np
.
float64
),
(
"
min
"
,
1
,
np
.
float64
),
(
"
max
"
,
1
,
np
.
float64
),
(
"
max
"
,
1
,
np
.
float64
),
(
"
any
"
,
1
,
np
.
float64
),
(
"
all
"
,
1
,
np
.
float64
),
# float + complex
# float + complex
(
"
sin
"
,
1
,
np
.
float64
),
(
"
sin
"
,
1
,
np
.
float64
),
...
@@ -519,6 +529,24 @@ def test_reductions_same_as_numpy(actx_factory, op):
...
@@ -519,6 +529,24 @@ def test_reductions_same_as_numpy(actx_factory, op):
assert
np
.
allclose
(
np_red
,
actx_red
)
assert
np
.
allclose
(
np_red
,
actx_red
)
@pytest.mark.parametrize
(
"
sym_name
"
,
[
"
any
"
,
"
all
"
])
def
test_any_all_same_as_numpy
(
actx_factory
,
sym_name
):
actx
=
actx_factory
()
if
not
hasattr
(
actx
.
np
,
sym_name
):
pytest
.
skip
(
f
"'
{
sym_name
}
'
not implemented on
'
{
type
(
actx
).
__name__
}
'"
)
rng
=
np
.
random
.
default_rng
()
ary_any
=
rng
.
integers
(
0
,
2
,
512
)
ary_all
=
np
.
ones
(
512
)
assert_close_to_numpy_in_containers
(
actx
,
lambda
_np
,
*
_args
:
getattr
(
_np
,
sym_name
)(
*
_args
),
[
ary_any
])
assert_close_to_numpy_in_containers
(
actx
,
lambda
_np
,
*
_args
:
getattr
(
_np
,
sym_name
)(
*
_args
),
[
ary_all
])
assert_close_to_numpy_in_containers
(
actx
,
lambda
_np
,
*
_args
:
getattr
(
_np
,
sym_name
)(
*
_args
),
[
1
-
ary_all
])
# }}}
# }}}
...
...
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