Commit e7a77f88 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

Merge branch 'master' into fft_op

parents 8b2b0c5c 5c5cbda2
......@@ -17,13 +17,14 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import abc
from nifty.nifty_meta import NiftyMeta
from keepers import Loggable,\
Versionable
class DomainObject(Versionable, Loggable, object):
__metaclass__ = abc.ABCMeta
__metaclass__ = NiftyMeta
def __init__(self):
# _global_id is used in the Versioning module from keepers
......
......@@ -16,10 +16,14 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from nifty.nifty_meta import NiftyMeta
from keepers import Loggable
class Energy(Loggable, object):
__metaclass__ = NiftyMeta
def __init__(self, position):
self._cache = {}
try:
......
......@@ -17,6 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import abc
from nifty.nifty_meta import NiftyMeta
import numpy as np
......@@ -26,7 +27,7 @@ from .line_searching import LineSearchStrongWolfe
class QuasiNewtonMinimizer(Loggable, object):
__metaclass__ = abc.ABCMeta
__metaclass__ = NiftyMeta
def __init__(self, line_searcher=LineSearchStrongWolfe(), callback=None,
convergence_tolerance=1E-4, convergence_level=3,
......
# -*- coding: utf-8 -*-
import abc
class DocStringInheritor(type):
"""
A variation on
http://groups.google.com/group/comp.lang.python/msg/26f7b4fcb4d66c95
by Paul McGuire
"""
def __new__(meta, name, bases, clsdict):
if not('__doc__' in clsdict and clsdict['__doc__']):
for mro_cls in (mro_cls for base in bases
for mro_cls in base.mro()):
doc = mro_cls.__doc__
if doc:
clsdict['__doc__'] = doc
break
for attr, attribute in clsdict.items():
if not attribute.__doc__:
for mro_cls in (mro_cls for base in bases
for mro_cls in base.mro()
if hasattr(mro_cls, attr)):
doc = getattr(getattr(mro_cls, attr), '__doc__')
if doc:
if isinstance(attribute, property):
clsdict[attr] = property(attribute.fget,
attribute.fset,
attribute.fdel,
doc)
else:
attribute.__doc__ = doc
break
return super(DocStringInheritor, meta).__new__(meta, name,
bases, clsdict)
class NiftyMeta(DocStringInheritor, abc.ABCMeta):
pass
......@@ -54,10 +54,6 @@ class ComposedOperator(LinearOperator):
self._target += op.target
return self._target
@property
def implemented(self):
return True
@property
def unitary(self):
return False
......
......@@ -30,13 +30,11 @@ class DiagonalOperator(EndomorphicOperator):
# ---Overwritten properties and methods---
def __init__(self, domain=(), implemented=True,
def __init__(self, domain=(),
diagonal=None, bare=False, copy=True,
distribution_strategy=None):
self._domain = self._parse_domain(domain)
self._implemented = bool(implemented)
if distribution_strategy is None:
if isinstance(diagonal, distributed_data_object):
distribution_strategy = diagonal.distribution_strategy
......@@ -100,10 +98,6 @@ class DiagonalOperator(EndomorphicOperator):
def domain(self):
return self._domain
@property
def implemented(self):
return self._implemented
@property
def self_adjoint(self):
if self._self_adjoint is None:
......@@ -144,16 +138,12 @@ class DiagonalOperator(EndomorphicOperator):
distribution_strategy=self.distribution_strategy,
copy=copy)
# weight if the given values were `bare` and `implemented` is True
# weight if the given values were `bare` is True
# do inverse weightening if the other way around
if bare and self.implemented:
if bare:
# If `copy` is True, we won't change external data by weightening
# Otherwise, inplace weightening would change the external field
f.weight(inplace=copy)
elif not bare and not self.implemented:
# If `copy` is True, we won't change external data by weightening
# Otherwise, inplace weightening would change the external field
f.weight(inplace=copy, power=-1)
# Reset the self_adjoint property:
self._self_adjoint = None
......
......@@ -225,10 +225,6 @@ class FFTOperator(LinearOperator):
def target(self):
return self._target
@property
def implemented(self):
return True
@property
def unitary(self):
return False
......
......@@ -17,6 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import abc
from nifty.nifty_meta import NiftyMeta
from keepers import Loggable
from nifty.field import Field
......@@ -24,7 +25,7 @@ import nifty.nifty_utilities as utilities
class LinearOperator(Loggable, object):
__metaclass__ = abc.ABCMeta
__metaclass__ = NiftyMeta
def __init__(self):
pass
......@@ -40,10 +41,6 @@ class LinearOperator(Loggable, object):
def target(self):
raise NotImplementedError
@abc.abstractproperty
def implemented(self):
raise NotImplementedError
@abc.abstractproperty
def unitary(self):
raise NotImplementedError
......@@ -54,9 +51,6 @@ class LinearOperator(Loggable, object):
def times(self, x, spaces=None, **kwargs):
spaces = self._check_input_compatibility(x, spaces)
if not self.implemented:
x = x.weight(spaces=spaces)
y = self._times(x, spaces, **kwargs)
return y
......@@ -64,8 +58,6 @@ class LinearOperator(Loggable, object):
spaces = self._check_input_compatibility(x, spaces, inverse=True)
y = self._inverse_times(x, spaces, **kwargs)
if not self.implemented:
y = y.weight(power=-1, spaces=spaces)
return y
def adjoint_times(self, x, spaces=None, **kwargs):
......@@ -74,8 +66,6 @@ class LinearOperator(Loggable, object):
spaces = self._check_input_compatibility(x, spaces, inverse=True)
if not self.implemented:
x = x.weight(spaces=spaces)
y = self._adjoint_times(x, spaces, **kwargs)
return y
......@@ -86,8 +76,6 @@ class LinearOperator(Loggable, object):
spaces = self._check_input_compatibility(x, spaces)
y = self._adjoint_inverse_times(x, spaces, **kwargs)
if not self.implemented:
y = y.weight(power=-1, spaces=spaces)
return y
def inverse_adjoint_times(self, x, spaces=None, **kwargs):
......@@ -97,8 +85,6 @@ class LinearOperator(Loggable, object):
spaces = self._check_input_compatibility(x, spaces)
y = self._inverse_adjoint_times(x, spaces)
if not self.implemented:
y = y.weight(power=-1, spaces=spaces)
return y
def _times(self, x, spaces):
......
......@@ -101,10 +101,6 @@ class ProjectionOperator(EndomorphicOperator):
def domain(self):
return self._projection_field.domain
@property
def implemented(self):
return True
@property
def unitary(self):
if self._unitary is None:
......
......@@ -74,10 +74,6 @@ class PropagatorOperator(InvertibleOperatorMixin, EndomorphicOperator):
def domain(self):
return self._domain
@property
def implemented(self):
return True
@property
def self_adjoint(self):
return True
......
......@@ -53,10 +53,6 @@ class SmoothingOperator(EndomorphicOperator):
def domain(self):
return self._domain
@property
def implemented(self):
return True
@property
def self_adjoint(self):
return True
......
from abc import ABCMeta, abstractmethod
from nifty.nifty_meta import NiftyMeta
class PlotlyWrapper(object):
__metaclass__ = ABCMeta
__metaclass__ = NiftyMeta
@abstractmethod
def to_plotly(self):
......
......@@ -16,8 +16,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import abc
import numpy as np
from nifty.field import Field
......@@ -38,8 +36,6 @@ class Prober(object):
"""
__metaclass__ = abc.ABCMeta
def __init__(self, domain=None, distribution_strategy=None, probe_count=8,
random_type='pm1', compute_variance=False):
......
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