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

cleanup

parent c91b2e9d
Pipeline #21748 passed with stage
in 4 minutes and 15 seconds
from __future__ import division from __future__ import division
from .version import __version__ from .version import __version__
from .field import Field from .field import *
from .domain_tuple import DomainTuple from .domain_tuple import DomainTuple
from .domain_object import DomainObject from .domain_object import DomainObject
from .basic_arithmetics import *
from .utilities import * from .utilities import *
from .field_types import * from .field_types import *
from .minimization import * from .minimization import *
......
# 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-2017 Max-Planck-Society
#
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from __future__ import division
from .field import Field
from . import dobj
__all__ = ['sqrt', 'exp', 'log', 'conjugate']
def _math_helper(x, function, out):
if not isinstance(x, Field):
raise TypeError("This function only accepts Field objects.")
if out is not None:
if not isinstance(out, Field) or x.domain != out.domain:
raise ValueError("Bad 'out' argument")
function(x.val, out=out.val)
return out
else:
return Field(domain=x.domain, val=function(x.val))
def sqrt(x, out=None):
return _math_helper(x, dobj.sqrt, out)
def exp(x, out=None):
return _math_helper(x, dobj.exp, out)
def log(x, out=None):
return _math_helper(x, dobj.log, out)
def conjugate(x, out=None):
return _math_helper(x, dobj.conjugate, out)
...@@ -24,6 +24,8 @@ from .domain_tuple import DomainTuple ...@@ -24,6 +24,8 @@ from .domain_tuple import DomainTuple
from functools import reduce from functools import reduce
from . import dobj from . import dobj
__all__ = ["Field", "sqrt", "exp", "log", "conjugate"]
class Field(object): class Field(object):
""" The discrete representation of a continuous field over multiple spaces. """ The discrete representation of a continuous field over multiple spaces.
...@@ -524,3 +526,33 @@ class Field(object): ...@@ -524,3 +526,33 @@ class Field(object):
"\n- val = " + repr(self.val) + \ "\n- val = " + repr(self.val) + \
"\n - min.,max. = " + str(minmax) + \ "\n - min.,max. = " + str(minmax) + \
"\n - mean = " + str(mean) "\n - mean = " + str(mean)
# Arithmetic functions working on Fields
def _math_helper(x, function, out):
if not isinstance(x, Field):
raise TypeError("This function only accepts Field objects.")
if out is not None:
if not isinstance(out, Field) or x.domain != out.domain:
raise ValueError("Bad 'out' argument")
function(x.val, out=out.val)
return out
else:
return Field(domain=x.domain, val=function(x.val))
def sqrt(x, out=None):
return _math_helper(x, dobj.sqrt, out)
def exp(x, out=None):
return _math_helper(x, dobj.exp, out)
def log(x, out=None):
return _math_helper(x, dobj.log, out)
def conjugate(x, out=None):
return _math_helper(x, dobj.conjugate, out)
from ..operators import EndomorphicOperator from ..operators import EndomorphicOperator
from ..utilities import memo from ..utilities import memo
from ..basic_arithmetics import exp from ..field import exp
from ..sugar import create_composed_fft_operator from ..sugar import create_composed_fft_operator
......
...@@ -19,8 +19,7 @@ ...@@ -19,8 +19,7 @@
from __future__ import division from __future__ import division
import numpy as np import numpy as np
from .space import Space from .space import Space
from .. import Field from ..field import Field, exp
from ..basic_arithmetics import exp
from .. import dobj from .. import dobj
......
...@@ -21,8 +21,7 @@ from builtins import range ...@@ -21,8 +21,7 @@ from builtins import range
from functools import reduce from functools import reduce
import numpy as np import numpy as np
from .space import Space from .space import Space
from .. import Field from ..field import Field, exp
from ..basic_arithmetics import exp
from .. import dobj from .. import dobj
......
...@@ -121,7 +121,6 @@ def power_analyze(field, spaces=None, binbounds=None, ...@@ -121,7 +121,6 @@ def power_analyze(field, spaces=None, binbounds=None,
def _compute_spec(field, spaces): def _compute_spec(field, spaces):
from .operators.power_projection_operator import PowerProjectionOperator from .operators.power_projection_operator import PowerProjectionOperator
from .basic_arithmetics import sqrt
if spaces is None: if spaces is None:
spaces = range(len(field.domain)) spaces = range(len(field.domain))
else: else:
......
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