Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
NIFTy
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
Container registry
Model registry
Monitor
Service Desk
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
ift
NIFTy
Commits
d38238db
Commit
d38238db
authored
4 years ago
by
Philipp Arras
Browse files
Options
Downloads
Patches
Plain Diff
Add helper functions for determining types
parent
36f0e20c
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!577
Helpful helpers
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/sugar.py
+31
-0
31 additions, 0 deletions
src/sugar.py
test/test_sugar.py
+16
-0
16 additions, 0 deletions
test/test_sugar.py
with
47 additions
and
0 deletions
src/sugar.py
+
31
−
0
View file @
d38238db
...
...
@@ -38,6 +38,7 @@ from .plot import Plot
__all__
=
[
'
PS_field
'
,
'
power_analyze
'
,
'
create_power_operator
'
,
'
create_harmonic_smoothing_operator
'
,
'
from_random
'
,
'
full
'
,
'
makeField
'
,
'
is_fieldlike
'
,
'
is_linearization
'
,
'
is_operator
'
,
'
makeDomain
'
,
'
get_signal_variance
'
,
'
makeOp
'
,
'
domain_union
'
,
'
get_default_codomain
'
,
'
single_plot
'
,
'
exec_time
'
,
'
calculate_position
'
]
+
list
(
pointwise
.
ptw_dict
.
keys
())
...
...
@@ -526,3 +527,33 @@ def calculate_position(operator, output):
kl
,
_
=
minimizer
(
kl
)
pos
=
kl
.
position
return
pos
def
is_operator
(
obj
):
"""
Checks if object is operator-like.
Note
----
A simple `isinstance(obj, ift.Operator)` does give the expected
result because, e.g., :class:`~nifty7.field.Field` inherits from
:class:`~nifty7.operators.operator.Operator`.
"""
return
isinstance
(
obj
,
Operator
)
and
obj
.
val
is
None
and
obj
.
jac
is
None
def
is_linearization
(
obj
):
"""
Checks if object is linearization-like.
"""
return
isinstance
(
obj
,
Operator
)
and
obj
.
val
is
not
None
and
obj
.
jac
is
not
None
def
is_fieldlike
(
obj
):
"""
Checks if object is field-like.
Note
----
A simple `isinstance(obj, ift.Field)` does give the expected
result because users might have implemented another class which
behaves field-like but is not an instance of
:class:`~nifty7.field.Field`.
"""
return
isinstance
(
obj
,
Operator
)
and
obj
.
val
is
not
None
and
obj
.
jac
is
None
This diff is collapsed.
Click to expand it.
test/test_sugar.py
+
16
−
0
View file @
d38238db
...
...
@@ -69,3 +69,19 @@ def test_calc_pos(mf, cplx):
fld
=
op
(
0.1
*
ift
.
from_random
(
op
.
domain
,
'
normal
'
))
pos
=
ift
.
calculate_position
(
op
,
fld
)
ift
.
extra
.
assert_allclose
(
op
(
pos
),
fld
,
1e-1
,
1e-1
)
def
test_isinstance_helpers
():
dom
=
ift
.
RGSpace
(
12
,
harmonic
=
True
)
op
=
ift
.
ScalingOperator
(
dom
,
12.
)
fld
=
ift
.
full
(
dom
,
0.
)
lin
=
ift
.
Linearization
.
make_var
(
fld
)
assert
not
ift
.
is_fieldlike
(
op
)
assert
not
ift
.
is_fieldlike
(
lin
)
assert
ift
.
is_fieldlike
(
fld
)
assert
not
ift
.
is_linearization
(
op
)
assert
ift
.
is_linearization
(
lin
)
assert
not
ift
.
is_linearization
(
fld
)
assert
ift
.
is_operator
(
op
)
assert
not
ift
.
is_operator
(
lin
)
assert
not
ift
.
is_operator
(
fld
)
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