Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ift
NIFTy
Commits
d02d1d26
Commit
d02d1d26
authored
Nov 28, 2020
by
Philipp Arras
Browse files
Add is_endo
parent
8b267e78
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/sugar.py
View file @
d02d1d26
...
...
@@ -38,7 +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'
,
'is_fieldlike'
,
'is_linearization'
,
'is_operator'
,
'is_endo'
,
'makeDomain'
,
'get_signal_variance'
,
'makeOp'
,
'domain_union'
,
'get_default_codomain'
,
'single_plot'
,
'exec_time'
,
'calculate_position'
]
+
list
(
pointwise
.
ptw_dict
.
keys
())
...
...
@@ -559,3 +559,22 @@ def is_fieldlike(obj):
:class:`~nifty7.linearization.Linearization` behave field-like.
"""
return
isinstance
(
obj
,
Operator
)
and
obj
.
val
is
not
None
def
is_endo
(
obj
):
"""Check if object is an endomorphic (linear) operator.
Note
----
A simple `isinstance(obj, ift.EndomorphicOperator)` does not cover all
cases. One counter example would be an `ChainOperator` where the domain of
the first sub operator and target of the last sub operator coincide.
"""
from
.operators.endomorphic_operator
import
EndomorphicOperator
from
.operators.linear_operator
import
LinearOperator
return
isinstance
(
obj
,
EndomorphicOperator
)
or
(
is_operator
(
obj
)
and
isinstance
(
obj
,
LinearOperator
)
and
obj
.
domain
==
obj
.
target
)
test/test_sugar.py
View file @
d02d1d26
...
...
@@ -85,3 +85,16 @@ def test_isinstance_helpers():
assert
ift
.
is_operator
(
op
)
assert
not
ift
.
is_operator
(
lin
)
assert
not
ift
.
is_operator
(
fld
)
assert
ift
.
is_endo
(
op
)
assert
not
ift
.
is_endo
(
lin
)
assert
not
ift
.
is_endo
(
fld
)
def
test_isendo
():
dom
=
ift
.
RGSpace
(
12
,
harmonic
=
True
)
op
=
ift
.
FFTOperator
(
dom
)
assert
not
ift
.
is_endo
(
op
)
assert
not
ift
.
is_endo
(
op
.
inverse
)
assert
not
ift
.
is_endo
(
op
.
adjoint
)
assert
ift
.
is_endo
(
op
@
op
.
adjoint
)
assert
ift
.
is_endo
(
op
@
op
.
inverse
)
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment