Commit cfcdd7d8 authored by theos's avatar theos

Modified nifty_field.py to successfully initialize with multiple spaces and a field_type.

Therefore made the Field_type base class more advanced.
Added default field dtype to nifty configuration.
parent 4ff7b806
......@@ -50,7 +50,8 @@ from nifty_paradict import space_paradict,\
point_space_paradict,\
nested_space_paradict
from field_types import Field_array
from field_types import Field_type,\
Field_array
from operators import *
......
# -*- coding: utf-8 -*-
import os
import numpy as np
import keepers
# Setup the dependency injector
......@@ -50,6 +50,21 @@ variable_verbosity = keepers.Variable('verbosity',
lambda z: z == abs(int(z)),
genus='int')
def _dtype_validator(dtype):
try:
np.dtype(dtype)
except(TypeError):
return False
else:
return True
variable_default_field_dtype = keepers.Variable(
'default_field_dtype',
['float'],
_dtype_validator,
genus='str')
variable_default_datamodel = keepers.Variable(
'default_datamodel',
['fftw', 'equal'],
......@@ -64,6 +79,7 @@ nifty_configuration = keepers.get_Configuration(
variable_use_healpy,
variable_use_libsharp,
variable_verbosity,
variable_default_field_dtype,
variable_default_datamodel,
],
path=os.path.expanduser('~') + "/.nifty/nifty_config")
......
# -*- coding: utf-8 -*-
from field_array import Field_array
\ No newline at end of file
from field_array import Field_type,\
Field_array
\ No newline at end of file
# -*- coding: utf-8 -*-
import numpy as np
class Base_field_type(object):
def __init__(self, shape):
self.shape = shape
@property
def shape(self):
return self._shape
@shape.setter
def shape(self, shape):
class Field_type(object):
def __init__(self, shape, dtype):
try:
new_shape = tuple([int(i) for i in shape])
except TypeError:
new_shape = (int(shape), )
self._shape = new_shape
self._dtype = np.dtype(dtype)
@property
def shape(self):
return self._shape
@property
def dtype(self):
return self._dtype
def get_dof(self, split=False):
if issubclass(self.dtype.type, np.complexfloating):
multiplicator = 2
else:
multiplicator = 1
if split:
dof = tuple(multiplicator*np.array(self.shape))
else:
dof = multiplicator*reduce(lambda x, y: x*y, self.shape)
return dof
def process(self, method_name, array, inplace=True, **kwargs):
try:
result_array = self.__getattr__(method_name)(array,
......@@ -29,3 +46,6 @@ class Base_field_type(object):
result_array = array.copy()
return result_array
def complement_cast(self, x, axis=None):
return x
# -*- coding: utf-8 -*-
from base_field_type import Base_field_type
from base_field_type import Field_type
class Field_array(Base_field_type):
class Field_array(Field_type):
pass
......@@ -311,7 +311,7 @@ class space(object):
raise NotImplementedError(about._errors.cstring(
"ERROR: no generic instance method 'dof'."))
def _complement_cast(self, x, axis=None):
def complement_cast(self, x, axis=None):
return x
# TODO: Move enforce power into power_indices class
......
This diff is collapsed.
......@@ -33,7 +33,8 @@ setup(name="ift_nifty",
description="Numerical Information Field Theory",
url="http://www.mpa-garching.mpg.de/ift/nifty/",
packages=["nifty", "nifty.demos", "nifty.rg", "nifty.lm",
"nifty.operators", "nifty.dummys", "nifty.config"],
"nifty.operators", "nifty.dummys", "nifty.field_types",
"nifty.config"],
package_dir={"nifty": ""},
zip_safe=False,
dependency_links=[
......
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