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

Fix ducktape behaviour

Closes #310
parent 9cbf7497
......@@ -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
# 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 <>.
# 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 = op.ducktape_left(a)
assert == ift.MultiDomain.make({a:})
assert op1.domain == op.domain
with pytest.raises(RuntimeError):
with pytest.raises(RuntimeError):
fld0 = fld.ducktape_left(a)
assert fld0.domain == mdom
lin0 = lin.ducktape_left(a)
assert lin0.domain == lin.domain
assert == mdom
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