multi_adaptor.py 1.36 KB
Newer Older
Philipp Arras's avatar
Philipp Arras committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# 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) 2013-2018 Max-Planck-Society
#
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.

Martin Reinecke's avatar
Martin Reinecke committed
19
from __future__ import absolute_import, division, print_function
20

Martin Reinecke's avatar
Martin Reinecke committed
21
from ..compat import *
Martin Reinecke's avatar
Martin Reinecke committed
22
from ..multi.multi_domain import MultiDomain
23
from .selection_operator import SelectionOperator
Philipp Arras's avatar
Philipp Arras committed
24 25


Martin Reinecke's avatar
Martin Reinecke committed
26 27
def MultiAdaptor(target):
    """Transforms a Field into a MultiField and vice versa when
28 29 30 31 32 33 34
    using adjoint_times.

    Parameters
    ----------
    target: MultiDomain
        MultiDomain with only one entry (key).
    """
Martin Reinecke's avatar
Martin Reinecke committed
35 36
    if not isinstance(target, MultiDomain) or len(target) > 1:
        raise TypeError
Martin Reinecke's avatar
Martin Reinecke committed
37
    return SelectionOperator(target, target.keys()[0]).adjoint