Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pyopencl
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
pyopencl
Commits
6842c798
Commit
6842c798
authored
3 years ago
by
Kaushik Kulkarni
Browse files
Options
Downloads
Patches
Plain Diff
extend cla.(maximum|minimum|if_positive) to take scalars
parent
3c8b103e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pyopencl/array.py
+28
-0
28 additions, 0 deletions
pyopencl/array.py
with
28 additions
and
0 deletions
pyopencl/array.py
+
28
−
0
View file @
6842c798
...
@@ -42,6 +42,9 @@ from pyopencl.compyte.array import (
...
@@ -42,6 +42,9 @@ from pyopencl.compyte.array import (
get_common_dtype
as
_get_common_dtype_base
)
get_common_dtype
as
_get_common_dtype_base
)
from
pyopencl.characterize
import
has_double_support
from
pyopencl.characterize
import
has_double_support
from
pyopencl
import
cltypes
from
pyopencl
import
cltypes
from
numbers
import
Number
SCALAR_CLASSES
=
(
Number
,
np
.
number
,
np
.
bool_
,
bool
)
_COMMON_DTYPE_CACHE
=
{}
_COMMON_DTYPE_CACHE
=
{}
...
@@ -2704,6 +2707,17 @@ def if_positive(criterion, then_, else_, out=None, queue=None):
...
@@ -2704,6 +2707,17 @@ def if_positive(criterion, then_, else_, out=None, queue=None):
contains *then_[i]* if *criterion[i]>0*, else *else_[i]*.
contains *then_[i]* if *criterion[i]>0*, else *else_[i]*.
"""
"""
if
all
(
isinstance
(
k
,
SCALAR_CLASSES
)
for
k
in
[
criterion
,
then_
,
else_
]):
result
=
np
.
where
(
criterion
,
then_
,
else_
)
if
out
is
not
None
:
out
[...]
=
result
return
return
result
if
not
(
criterion
.
shape
==
then_
.
shape
==
else_
.
shape
):
if
not
(
criterion
.
shape
==
then_
.
shape
==
else_
.
shape
):
raise
ValueError
(
"
shapes do not match
"
)
raise
ValueError
(
"
shapes do not match
"
)
...
@@ -2719,6 +2733,13 @@ def if_positive(criterion, then_, else_, out=None, queue=None):
...
@@ -2719,6 +2733,13 @@ def if_positive(criterion, then_, else_, out=None, queue=None):
def
maximum
(
a
,
b
,
out
=
None
,
queue
=
None
):
def
maximum
(
a
,
b
,
out
=
None
,
queue
=
None
):
"""
Return the elementwise maximum of *a* and *b*.
"""
"""
Return the elementwise maximum of *a* and *b*.
"""
if
all
(
isinstance
(
k
,
SCALAR_CLASSES
)
for
k
in
[
a
,
b
]):
result
=
np
.
maximum
(
a
,
b
)
if
out
is
not
None
:
out
[...]
=
result
return
return
result
# silly, but functional
# silly, but functional
return
if_positive
(
a
.
mul_add
(
1
,
b
,
-
1
,
queue
=
queue
),
a
,
b
,
return
if_positive
(
a
.
mul_add
(
1
,
b
,
-
1
,
queue
=
queue
),
a
,
b
,
...
@@ -2727,6 +2748,13 @@ def maximum(a, b, out=None, queue=None):
...
@@ -2727,6 +2748,13 @@ def maximum(a, b, out=None, queue=None):
def
minimum
(
a
,
b
,
out
=
None
,
queue
=
None
):
def
minimum
(
a
,
b
,
out
=
None
,
queue
=
None
):
"""
Return the elementwise minimum of *a* and *b*.
"""
"""
Return the elementwise minimum of *a* and *b*.
"""
if
all
(
isinstance
(
k
,
SCALAR_CLASSES
)
for
k
in
[
a
,
b
]):
result
=
np
.
minimum
(
a
,
b
)
if
out
is
not
None
:
out
[...]
=
result
return
return
result
# silly, but functional
# silly, but functional
return
if_positive
(
a
.
mul_add
(
1
,
b
,
-
1
,
queue
=
queue
),
b
,
a
,
return
if_positive
(
a
.
mul_add
(
1
,
b
,
-
1
,
queue
=
queue
),
b
,
a
,
queue
=
queue
,
out
=
out
)
queue
=
queue
,
out
=
out
)
...
...
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