Commit 9283df01 authored by Martin Reinecke's avatar Martin Reinecke

small tweaks

parent 97829024
...@@ -214,14 +214,14 @@ class Field(object): ...@@ -214,14 +214,14 @@ class Field(object):
"""Field : The real part of the field""" """Field : The real part of the field"""
if not np.issubdtype(self.dtype, np.complexfloating): if not np.issubdtype(self.dtype, np.complexfloating):
return self return self
return Field(self._domain, self.val.real) return Field(self._domain, self._val.real)
@property @property
def imag(self): def imag(self):
"""Field : The imaginary part of the field""" """Field : The imaginary part of the field"""
if not np.issubdtype(self.dtype, np.complexfloating): if not np.issubdtype(self.dtype, np.complexfloating):
raise ValueError(".imag called on a non-complex Field") raise ValueError(".imag called on a non-complex Field")
return Field(self._domain, self.val.imag) return Field(self._domain, self._val.imag)
def scalar_weight(self, spaces=None): def scalar_weight(self, spaces=None):
"""Returns the uniform volume element for a sub-domain of `self`. """Returns the uniform volume element for a sub-domain of `self`.
...@@ -344,7 +344,7 @@ class Field(object): ...@@ -344,7 +344,7 @@ class Field(object):
spaces = utilities.parse_spaces(spaces, ndom) spaces = utilities.parse_spaces(spaces, ndom)
if len(spaces) == ndom: if len(spaces) == ndom:
return dobj.vdot(self.val, x.val) return dobj.vdot(self._val, x._val)
# If we arrive here, we have to do a partial dot product. # If we arrive here, we have to do a partial dot product.
# For the moment, do this the explicit, non-optimized way # For the moment, do this the explicit, non-optimized way
return (self.conjugate()*x).sum(spaces=spaces) return (self.conjugate()*x).sum(spaces=spaces)
...@@ -377,7 +377,7 @@ class Field(object): ...@@ -377,7 +377,7 @@ class Field(object):
Field Field
The complex conjugated field. The complex conjugated field.
""" """
return Field(self._domain, self.val.conjugate()) return Field(self._domain, self._val.conjugate())
# ---General unary/contraction methods--- # ---General unary/contraction methods---
...@@ -385,14 +385,14 @@ class Field(object): ...@@ -385,14 +385,14 @@ class Field(object):
return self return self
def __neg__(self): def __neg__(self):
return Field(self._domain, -self.val) return Field(self._domain, -self._val)
def __abs__(self): def __abs__(self):
return Field(self._domain, abs(self.val)) return Field(self._domain, abs(self._val))
def _contraction_helper(self, op, spaces): def _contraction_helper(self, op, spaces):
if spaces is None: if spaces is None:
return getattr(self.val, op)() return getattr(self._val, op)()
spaces = utilities.parse_spaces(spaces, len(self._domain)) spaces = utilities.parse_spaces(spaces, len(self._domain))
...@@ -402,7 +402,7 @@ class Field(object): ...@@ -402,7 +402,7 @@ class Field(object):
axes_list = reduce(lambda x, y: x+y, axes_list) axes_list = reduce(lambda x, y: x+y, axes_list)
# perform the contraction on the data # perform the contraction on the data
data = getattr(self.val, op)(axis=axes_list) data = getattr(self._val, op)(axis=axes_list)
# check if the result is scalar or if a result_field must be constr. # check if the result is scalar or if a result_field must be constr.
if np.isscalar(data): if np.isscalar(data):
...@@ -593,7 +593,7 @@ class Field(object): ...@@ -593,7 +593,7 @@ class Field(object):
def __str__(self): def __str__(self):
return "nifty5.Field instance\n- domain = " + \ return "nifty5.Field instance\n- domain = " + \
self._domain.__str__() + \ self._domain.__str__() + \
"\n- val = " + repr(self.val) "\n- val = " + repr(self._val)
def isEquivalentTo(self, other): def isEquivalentTo(self, other):
"""Determines (as quickly as possible) whether `self`'s content is """Determines (as quickly as possible) whether `self`'s content is
...@@ -626,12 +626,12 @@ for op in ["__add__", "__radd__", ...@@ -626,12 +626,12 @@ for op in ["__add__", "__radd__",
if isinstance(other, Field): if isinstance(other, Field):
if other._domain is not self._domain: if other._domain is not self._domain:
raise ValueError("domains are incompatible.") raise ValueError("domains are incompatible.")
tval = getattr(self.val, op)(other.val) tval = getattr(self._val, op)(other._val)
return Field(self._domain, tval) return Field(self._domain, tval)
if (np.isscalar(other) or if (np.isscalar(other) or
isinstance(other, (dobj.data_object, np.ndarray))): isinstance(other, (dobj.data_object, np.ndarray))):
tval = getattr(self.val, op)(other) tval = getattr(self._val, op)(other)
return Field(self._domain, tval) return Field(self._domain, tval)
raise TypeError("should not arrive here") raise TypeError("should not arrive here")
......
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