Commit fa08ba32 authored by Philipp Arras's avatar Philipp Arras
Browse files

Fixups discussed with Reimar

parent f35fdf5a
......@@ -25,6 +25,7 @@ from .linearization import Linearization
from .multi_domain import MultiDomain
from .multi_field import MultiField
from .operators.adder import Adder
from .operators.endomorphic_operator import EndomorphicOperator
from .operators.energy_operators import EnergyOperator
from .operators.linear_operator import LinearOperator
from .operators.operator import Operator
......@@ -201,7 +202,7 @@ def _domain_check_linear(op, domain_dtype=None, inp=None):
def _check_sqrt(op, domain_dtype):
if not is_endo(op):
if not isinstance(op, EndomorphicOperator):
try:
op.get_sqrt()
raise RuntimeError("Operator implements get_sqrt() although it is not an endomorphic operator.")
......@@ -209,7 +210,7 @@ def _check_sqrt(op, domain_dtype):
return
try:
sqop = op.get_sqrt()
except (NotImplementedError, AttributeError):
except NotImplementedError:
return
fld = from_random(op.domain, dtype=domain_dtype)
a = op(fld)
......
......@@ -52,10 +52,7 @@ class BlockDiagonalOperator(EndomorphicOperator):
for ii, kk in enumerate(self._domain.keys()):
if self._ops[ii] is None:
continue
try:
ops[kk] = self._ops[ii].get_sqrt()
except AttributeError:
raise NotImplementedError
ops[kk] = self._ops[ii].get_sqrt()
return BlockDiagonalOperator(self._domain, ops)
def apply(self, x, mode):
......
......@@ -168,7 +168,7 @@ class DiagonalOperator(EndomorphicOperator):
def get_sqrt(self):
if not np.iscomplexobj(self._ldiag) or (self._ldiag < 0).any():
raise NotImplementedError
raise ValueError("get_sqrt() works only for positive definite operators.")
return self._from_ldiag((), np.sqrt(self._ldiag))
def __repr__(self):
......
......@@ -98,7 +98,7 @@ class ScalingOperator(EndomorphicOperator):
def get_sqrt(self):
fct = self._get_fct(False)
if np.iscomplexobj(fct) or fct < 0:
raise NotImplementedError
raise ValueError("get_sqrt() works only for positive definite operators.")
return ScalingOperator(self._domain, fct)
def __call__(self, other):
......
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