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
Andreas Klöckner
arraycontext
Commits
fb26aaf0
Commit
fb26aaf0
authored
3 years ago
by
Alexandru Fikl
Committed by
Andreas Klöckner
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
use np.isscalar instead of isinstance(x, Number)
parent
56b2f1ed
No related branches found
No related tags found
No related merge requests found
Pipeline
#229787
passed
3 years ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
arraycontext/fake_numpy.py
+4
-7
4 additions, 7 deletions
arraycontext/fake_numpy.py
with
4 additions
and
7 deletions
arraycontext/fake_numpy.py
+
4
−
7
View file @
fb26aaf0
...
...
@@ -147,8 +147,7 @@ class BaseFakeNumpyNamespace:
def
__getattr__
(
self
,
name
):
def
loopy_implemented_elwise_func
(
*
args
):
from
numbers
import
Number
if
all
(
isinstance
(
ary
,
Number
)
for
ary
in
args
):
if
all
(
np
.
isscalar
(
ary
)
for
ary
in
args
):
return
getattr
(
np
,
name
)(
*
args
)
actx
=
self
.
_array_context
...
...
@@ -175,8 +174,7 @@ class BaseFakeNumpyNamespace:
raise
AttributeError
(
name
)
def
_new_like
(
self
,
ary
,
alloc_like
):
from
numbers
import
Number
if
isinstance
(
ary
,
Number
):
if
np
.
isscalar
(
ary
):
# NOTE: `np.zeros_like(x)` returns `array(x, shape=())`, which
# is best implemented by concrete array contexts, if at all
raise
NotImplementedError
(
"
operation not implemented for scalars
"
)
...
...
@@ -233,9 +231,7 @@ class BaseFakeNumpyLinalgNamespace:
self
.
_array_context
=
array_context
def
norm
(
self
,
ary
,
ord
=
None
):
from
numbers
import
Number
if
isinstance
(
ary
,
Number
):
if
np
.
isscalar
(
ary
):
return
abs
(
ary
)
actx
=
self
.
_array_context
...
...
@@ -274,6 +270,7 @@ class BaseFakeNumpyLinalgNamespace:
if
ary
.
size
==
0
:
return
ary
.
dtype
.
type
(
0
)
from
numbers
import
Number
if
ord
==
2
:
return
actx
.
np
.
sqrt
(
actx
.
np
.
sum
(
abs
(
ary
)
**
2
))
if
ord
==
np
.
inf
:
...
...
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