Commit 753bb188 authored by Philipp Arras's avatar Philipp Arras
Browse files

Fix ducktape behaviour

Closes #310
parent 9cbf7497
Pipeline #88090 passed with stages
in 14 minutes
......@@ -260,12 +260,19 @@ class Operator(metaclass=NiftyMeta):
return self @ x
def ducktape(self, name):
from ..sugar import is_operator
from .simple_linear_operators import ducktape
if not is_operator(self):
raise RuntimeError("ducktape works only on operators")
return self @ ducktape(self, None, name)
def ducktape_left(self, name):
from .simple_linear_operators import ducktape
return ducktape(None, self, name) @ self
from ..sugar import is_operator, is_fieldlike, is_linearization
if is_operator(self):
return ducktape(None, self, name) @ self
if is_fieldlike(self) or is_linearization(self):
return ducktape(None, self.domain, name)(self)
def __repr__(self):
return self.__class__.__name__
......
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright(C) 2020 Max-Planck-Society
#
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik.
import numpy as np
from numpy.testing import assert_allclose
import nifty7 as ift
import pytest
from ..common import setup_function, teardown_function
def test_ducktape():
dom = ift.RGSpace(10)
op = ift.FFTOperator(dom)
fld = ift.full(dom, 2.)
lin = ift.Linearization.make_var(fld)
a = "foo"
op1 = op.ducktape(a)
mdom = ift.MultiDomain.make({a: dom})
assert op1.domain == mdom
assert op1.target == op.target
op1 = op.ducktape_left(a)
assert op1.target == ift.MultiDomain.make({a: op.target})
assert op1.domain == op.domain
with pytest.raises(RuntimeError):
fld.ducktape(a)
with pytest.raises(RuntimeError):
lin.ducktape(a)
fld0 = fld.ducktape_left(a)
assert fld0.domain == mdom
lin0 = lin.ducktape_left(a)
assert lin0.domain == lin.domain
assert lin0.target == mdom
Markdown is supported
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