Commit 43cc5bfd authored by Martin Reinecke's avatar Martin Reinecke
Browse files

Merge branch 'imag_operator' into 'NIFTy_6'

Imag operator

See merge request !481
parents 2990b099 9953fdbd
Pipeline #75294 passed with stages
in 8 minutes and 40 seconds
......@@ -44,7 +44,7 @@ from .operators.block_diagonal_operator import BlockDiagonalOperator
from .operators.outer_product_operator import OuterProduct
from .operators.simple_linear_operators import (
VdotOperator, ConjugationOperator, Realizer, FieldAdapter, ducktape,
GeometryRemover, NullOperator, PartialExtractor)
GeometryRemover, NullOperator, PartialExtractor, Imaginizer)
from .operators.matrix_product_operator import MatrixProductOperator
from .operators.value_inserter import ValueInserter
from .operators.energy_operators import (
......@@ -709,6 +709,7 @@ class Field(Operator):
tmp = ptw_dict[op][1](self._val, *argstmp, **kwargstmp)
return (Field(self._domain, tmp[0]), Field(self._domain, tmp[1]))
for op in ["__add__", "__radd__",
"__sub__", "__rsub__",
"__mul__", "__rmul__",
......@@ -133,6 +133,10 @@ class Linearization(Operator):
def real(self):
return, self._jac.real)
def imag(self):
return, self._jac.imag)
def _myadd(self, other, neg):
if np.isscalar(other) or other.jac is None:
return if neg else self._val+other,
......@@ -168,7 +168,6 @@ class LinearOperator(Operator):
def __call__(self, x):
"""Same as :meth:`times`"""
from ..linearization import Linearization
if x.jac is not None:
return, self).prepend_jac(x.jac)
if x.val is not None:
......@@ -149,6 +149,11 @@ class Operator(metaclass=NiftyMeta):
from .simple_linear_operators import Realizer
return Realizer(
def imag(self):
from .simple_linear_operators import Imaginizer
return Imaginizer(
def __neg__(self):
return self.scale(-1)
......@@ -112,6 +112,26 @@ class Realizer(EndomorphicOperator):
return x.real
class Imaginizer(EndomorphicOperator):
"""Operator returning the imaginary component of its input.
domain: Domain, tuple of domains or DomainTuple
domain of the input field
def __init__(self, domain):
self._domain = DomainTuple.make(domain)
self._capability = self.TIMES | self.ADJOINT_TIMES
def apply(self, x, mode):
self._check_input(x, mode)
if mode == self.TIMES:
return x.imag
return 1j*x
class FieldAdapter(LinearOperator):
"""Operator for conversion between Fields and MultiFields.
......@@ -82,6 +82,13 @@ def testRealizer(sp):
@pmp('sp', _h_spaces + _p_spaces + _pow_spaces)
def testImaginizer(sp):
op = ift.Imaginizer(sp)
ift.extra.consistency_check(op, np.complex128, np.float64,
@pmp('sp', _h_spaces + _p_spaces + _pow_spaces)
def testConjugationOperator(sp):
op = ift.ConjugationOperator(sp)
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