Commit bbd1c13e authored by theos's avatar theos
Browse files

Renamed 'datamodel' to 'distribution_strategy'.

parent c3c16adb
......@@ -80,8 +80,8 @@ variable_default_field_dtype = keepers.Variable(
_dtype_validator,
genus='str')
variable_default_datamodel = keepers.Variable(
'default_datamodel',
variable_default_distribution_strategy = keepers.Variable(
'default_distribution_strategy',
['fftw', 'equal'],
lambda z: (('pyfftw' in dependency_injector)
if z == 'fftw' else True),
......@@ -95,7 +95,7 @@ nifty_configuration = keepers.get_Configuration(
variable_use_libsharp,
variable_verbosity,
variable_default_field_dtype,
variable_default_datamodel,
variable_default_distribution_strategy,
],
path=os.path.expanduser('~') + "/.nifty/nifty_config")
########
......
......@@ -25,7 +25,7 @@ class Field(object):
# ---Initialization methods---
def __init__(self, domain=None, val=None, dtype=None, field_type=None,
datamodel=None, copy=False):
distribution_strategy=None, copy=False):
self.domain = self._parse_domain(domain=domain, val=val)
self.domain_axes = self._get_axes_tuple(self.domain)
......@@ -44,7 +44,8 @@ class Field(object):
domain=self.domain,
field_type=self.field_type)
self.datamodel = self._parse_datamodel(datamodel=datamodel,
self.distribution_strategy = self._parse_distribution_strategy(
distribution_strategy=distribution_strategy,
val=val)
self.set_val(new_val=val, copy=copy)
......@@ -111,28 +112,28 @@ class Field(object):
return dtype
def _parse_datamodel(self, datamodel, val):
if datamodel is None:
def _parse_distribution_strategy(self, distribution_strategy, val):
if distribution_strategy is None:
if isinstance(val, distributed_data_object):
datamodel = val.distribution_strategy
distribution_strategy = val.distribution_strategy
elif isinstance(val, Field):
datamodel = val.datamodel
distribution_strategy = val.distribution_strategy
else:
about.warnings.cprint("WARNING: Datamodel set to default!")
datamodel = gc['default_datamodel']
elif datamodel not in DISTRIBUTION_STRATEGIES['all']:
distribution_strategy = gc['default_distribution_strategy']
elif distribution_strategy not in DISTRIBUTION_STRATEGIES['all']:
raise ValueError(about._errors.cstring(
"ERROR: Invalid datamodel!"))
return datamodel
"ERROR: Invalid distribution_strategy!"))
return distribution_strategy
# ---Factory methods---
@classmethod
def from_random(cls, random_type, domain=None, dtype=None, field_type=None,
datamodel=None, **kwargs):
distribution_strategy=None, **kwargs):
# create a initially empty field
f = cls(domain=domain, dtype=dtype, field_type=field_type,
datamodel=datamodel)
distribution_strategy=distribution_strategy)
# now use the processed input in terms of f in order to parse the
# random arguments
......@@ -229,7 +230,7 @@ class Field(object):
harmonic_domain = self.domain[space_index]
power_domain = PowerSpace(harmonic_domain=harmonic_domain,
datamodel=distribution_strategy,
distribution_strategy=distribution_strategy,
log=log, nbin=nbin, binbounds=binbounds,
dtype=power_dtype)
......@@ -358,11 +359,12 @@ class Field(object):
else:
result_list = [None]
result_list = [self.__class__.from_random('normal',
result_list = [self.__class__.from_random(
'normal',
result_domain,
dtype=harmonic_domain.dtype,
field_type=self.field_type,
datamodel=self.datamodel)
distribution_strategy=self.distribution_strategy)
for x in result_list]
# from now on extract the values from the random fields for further
......@@ -514,22 +516,23 @@ class Field(object):
return_x = distributed_data_object(
global_shape=self.shape,
dtype=dtype,
distribution_strategy=self.datamodel)
distribution_strategy=self.distribution_strategy)
return_x.set_full_data(x, copy=False)
return return_x
def copy(self, domain=None, dtype=None, field_type=None,
datamodel=None):
distribution_strategy=None):
copied_val = self.get_val(copy=True)
new_field = self.copy_empty(domain=domain,
new_field = self.copy_empty(
domain=domain,
dtype=dtype,
field_type=field_type,
datamodel=datamodel)
distribution_strategy=distribution_strategy)
new_field.set_val(new_val=copied_val, copy=False)
return new_field
def copy_empty(self, domain=None, dtype=None, field_type=None,
datamodel=None):
distribution_strategy=None):
if domain is None:
domain = self.domain
else:
......@@ -545,8 +548,8 @@ class Field(object):
else:
field_type = self._parse_field_type(field_type)
if datamodel is None:
datamodel = self.datamodel
if distribution_strategy is None:
distribution_strategy = self.distribution_strategy
fast_copyable = True
try:
......@@ -562,13 +565,13 @@ class Field(object):
fast_copyable = False
if (fast_copyable and dtype == self.dtype and
datamodel == self.datamodel):
distribution_strategy == self.distribution_strategy):
new_field = self._fast_copy_empty()
else:
new_field = Field(domain=domain,
dtype=dtype,
field_type=field_type,
datamodel=datamodel)
distribution_strategy=distribution_strategy)
return new_field
def _fast_copy_empty(self):
......
......@@ -16,26 +16,63 @@ class DiagonalOperator(EndomorphicOperator):
# ---Overwritten properties and methods---
def __init__(self, domain=(), field_type=(), implemented=False,
diagonal=None, bare=False, copy=True, datamodel=None):
diagonal=None, bare=False, copy=True,
distribution_strategy=None):
super(DiagonalOperator, self).__init__(domain=domain,
field_type=field_type,
implemented=implemented)
self._implemented = bool(implemented)
if datamodel is None:
if distribution_strategy is None:
if isinstance(diagonal, distributed_data_object):
datamodel = diagonal.distribution_strategy
distribution_strategy = diagonal.distribution_strategy
elif isinstance(diagonal, Field):
datamodel = diagonal.datamodel
distribution_strategy = diagonal.distribution_strategy
self.datamodel = self._parse_datamodel(datamodel=datamodel,
self.distribution_strategy = self._parse_distribution_strategy(
distribution_strategy=distribution_strategy,
val=diagonal)
self.set_diagonal(diagonal=diagonal, bare=bare, copy=copy)
def _times(self, x, spaces, types):
pass
# if the distribution_strategy of self is sub-slice compatible to
# the one of x, reshape the local data of self and apply it directly
active_axes = []
if spaces is None:
for axes in x.domain_axes:
active_axes += axes
else:
for space_index in spaces:
active_axes += x.domain_axes[space_index]
if types is None:
for axes in x.field_type_axes:
active_axes += axes
else:
for type_index in types:
active_axes += x.field_type_axes[type_index]
if x.val.get_axes_local_distribution_strategy(active_axes) == \
self.distribution_strategy:
local_data = self._diagonal.val.get_local_data(copy=False)
# check if domains match completely
# -> multiply directly
# check if axes_local_distribution_strategy matches.
# If yes, extract local data of self.diagonal and x and use numpy
# reshape.
# assert that indices in spaces and types are striktly increasing
# otherwise a wild transpose would be necessary
# build new shape (1,1,x,1,y,1,1,z)
# copy self.diagonal into new shape
# apply reshaped array to x
def _adjoint_times(self, x, spaces, types):
pass
......@@ -97,29 +134,29 @@ class DiagonalOperator(EndomorphicOperator):
# ---Added properties and methods---
@property
def datamodel(self):
return self._datamodel
def distribution_strategy(self):
return self._distribution_strategy
def _parse_datamodel(self, datamodel, val):
if datamodel is None:
def _parse_distribution_strategy(self, distribution_strategy, val):
if distribution_strategy is None:
if isinstance(val, distributed_data_object):
datamodel = val.distribution_strategy
distribution_strategy = val.distribution_strategy
elif isinstance(val, Field):
datamodel = val.datamodel
distribution_strategy = val.distribution_strategy
else:
about.warnings.cprint("WARNING: Datamodel set to default!")
datamodel = gc['default_datamodel']
elif datamodel not in DISTRIBUTION_STRATEGIES['all']:
distribution_strategy = gc['default_distribution_strategy']
elif distribution_strategy not in DISTRIBUTION_STRATEGIES['all']:
raise ValueError(about._errors.cstring(
"ERROR: Invalid datamodel!"))
return datamodel
"ERROR: Invalid distribution_strategy!"))
return distribution_strategy
def set_diagonal(self, diagonal, bare=False, copy=True):
# use the casting functionality from Field to process `diagonal`
f = Field(domain=self.domain,
val=diagonal,
field_type=self.field_type,
datamodel=self.datamodel,
distribution_strategy=self.distribution_strategy,
copy=copy)
# weight if the given values were `bare` and `implemented` is True
......
......@@ -157,8 +157,7 @@ class LinearOperator(object):
# cases:
# 1. Case:
# The user specifies with `spaces` that the operators domain should
# be applied to a certain domain in the domain-tuple of x. This is
# only valid if len(self.domain)==1.
# be applied to certain spaces in the domain-tuple of x.
# 2. Case:
# The domains of self and x match completely.
......@@ -175,16 +174,8 @@ class LinearOperator(object):
"ERROR: The operator's and and field's domains don't "
"match."))
else:
if len(self_domain) > 1:
raise ValueError(about._errors.cstring(
"ERROR: Specifying `spaces` for operators with multiple "
"domain spaces is not valid."))
elif len(spaces) != len(self_domain):
raise ValueError(about._errors.cstring(
"ERROR: Length of `spaces` does not match the number of "
"spaces in the operator's domain."))
elif len(spaces) == 1:
if x.domain[spaces[0]] != self_domain[0]:
for i, space_index in enumerate(spaces):
if x.domain[space_index] != self_domain[i]:
raise ValueError(about._errors.cstring(
"ERROR: The operator's and and field's domains don't "
"match."))
......@@ -195,19 +186,12 @@ class LinearOperator(object):
"ERROR: The operator's and and field's field_types don't "
"match."))
else:
if len(self_field_type) > 1:
raise ValueError(about._errors.cstring(
"ERROR: Specifying `types` for operators with multiple "
"field-types is not valid."))
elif len(types) != len(self_field_type):
raise ValueError(about._errors.cstring(
"ERROR: Length of `types` does not match the number of "
"the operator's field-types."))
elif len(types) == 1:
if x.field_type[types[0]] != self_field_type[0]:
for i, field_type_index in enumerate(types):
if x.field_types[field_type_index] != self_field_type[i]:
raise ValueError(about._errors.cstring(
"ERROR: The operator's and and field's field_type "
"don't match."))
return (spaces, types)
def __repr__(self):
......
......@@ -2840,7 +2840,7 @@ class response_operator(operator):
# TODO: Fix the target spaces
target = Space(assignments,
dtype=self.domain.dtype,
datamodel=self.domain.datamodel)
distribution_strategy=self.domain.distribution_strategy)
else:
# check target
if not isinstance(target, Space):
......
......@@ -499,7 +499,7 @@ class LMSpace(Space):
raise ValueError(about._errors.cstring(
"ERROR: unsupported codomain."))
# if self.datamodel != 'not':
# if self.distribution_strategy != 'not':
# about.warnings.cprint(
# "WARNING: Field data is consolidated to all nodes for "
# "external alm2map method!")
......@@ -569,7 +569,7 @@ class LMSpace(Space):
elif sigma < 0:
raise ValueError(about._errors.cstring("ERROR: invalid sigma."))
# if self.datamodel != 'not':
# if self.distribution_strategy != 'not':
# about.warnings.cprint(
# "WARNING: Field data is consolidated to all nodes for "
# "external smoothalm method!")
......@@ -612,7 +612,7 @@ class LMSpace(Space):
lmax = self.paradict['lmax']
mmax = self.paradict['mmax']
# if self.datamodel != 'not':
# if self.distribution_strategy != 'not':
# about.warnings.cprint(
# "WARNING: Field data is consolidated to all nodes for "
# "external anaalm/alm2cl method!")
......
......@@ -14,7 +14,7 @@ class PowerSpace(Space):
# ---Overwritten properties and methods---
def __init__(self, harmonic_domain=RGSpace((1,)), datamodel='not',
def __init__(self, harmonic_domain=RGSpace((1,)), distribution_strategy='not',
log=False, nbin=None, binbounds=None,
dtype=np.dtype('float')):
......@@ -31,7 +31,7 @@ class PowerSpace(Space):
power_index = PowerIndexFactory.get_power_index(
domain=self.harmonic_domain,
distribution_strategy=datamodel,
distribution_strategy=distribution_strategy,
log=log,
nbin=nbin,
binbounds=binbounds)
......@@ -71,9 +71,9 @@ class PowerSpace(Space):
return reduce(lambda x, y: x*y, self.pindex.shape)
def copy(self):
datamodel = self.pindex.distribution_strategy
distribution_strategy = self.pindex.distribution_strategy
return self.__class__(harmonic_domain=self.harmonic_domain,
datamodel=datamodel,
distribution_strategy=distribution_strategy,
log=self.log,
nbin=self.nbin,
binbounds=self.binbounds,
......
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