Commit 0ce1b2ee authored by Martin Reinecke's avatar Martin Reinecke
Browse files

Merge branch 'expressive_errors' into 'NIFTy_5'

More expressive error messages for domain checks.

See merge request ift/nifty-dev!121
parents bd249a5f 25275186
...@@ -259,5 +259,4 @@ class LinearOperator(Operator): ...@@ -259,5 +259,4 @@ class LinearOperator(Operator):
def _check_input(self, x, mode): def _check_input(self, x, mode):
self._check_mode(mode) self._check_mode(mode)
if self._dom(mode) != x.domain: self._check_domain_equality(self._dom(mode), x.domain)
raise ValueError("The operator's and field's domains don't match.")
...@@ -32,6 +32,15 @@ from .linear_operator import LinearOperator ...@@ -32,6 +32,15 @@ from .linear_operator import LinearOperator
# collect the unstructured Fields. # collect the unstructured Fields.
class MaskOperator(LinearOperator): class MaskOperator(LinearOperator):
def __init__(self, mask): def __init__(self, mask):
"""Implementation of a mask response
This operator takes a field, applies a mask and returns the values of
the field in a UnstructuredDomain. It can be used as response operator.
Parameters
----------
mask : Field
"""
if not isinstance(mask, Field): if not isinstance(mask, Field):
raise TypeError raise TypeError
......
...@@ -23,6 +23,17 @@ class Operator(NiftyMetaBase()): ...@@ -23,6 +23,17 @@ class Operator(NiftyMetaBase()):
The domain on which the Operator's output Field lives.""" The domain on which the Operator's output Field lives."""
return self._target return self._target
@staticmethod
def _check_domain_equality(dom_op, dom_field):
if dom_op != dom_field:
s = "The operator's and field's domains don't match."
from ..domain_tuple import DomainTuple
from ..multi_domain import MultiDomain
if not isinstance(dom_op, [DomainTuple, MultiDomain]):
s += " Your operator's domain is neither a `DomainTuple`" \
" nor a `MultiDomain`."
raise ValueError(s)
def scale(self, factor): def scale(self, factor):
if factor == 1: if factor == 1:
return self return self
...@@ -66,8 +77,7 @@ class Operator(NiftyMetaBase()): ...@@ -66,8 +77,7 @@ class Operator(NiftyMetaBase()):
def _check_input(self, x): def _check_input(self, x):
from ..linearization import Linearization from ..linearization import Linearization
d = x.target if isinstance(x, Linearization) else x.domain d = x.target if isinstance(x, Linearization) else x.domain
if self._domain != d: self._check_domain_equality(self._domain, d)
raise ValueError("The operator's and field's domains don't match.")
def __call__(self, x): def __call__(self, x):
if isinstance(x, Operator): if isinstance(x, Operator):
......
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