Commit d02d1d26 authored by Philipp Arras's avatar Philipp Arras
Browse files

Add is_endo

parent 8b267e78
......@@ -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.
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 (
and isinstance(obj, LinearOperator)
and obj.domain ==
......@@ -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)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment