Commit bc3f10ca authored by csongor's avatar csongor
Browse files

WIP: remove datamodel from spaces.

parent 5cbe6880
......@@ -121,7 +121,7 @@ class lm_space(point_space):
"""
def __init__(self, lmax, mmax=None, dtype=np.dtype('complex128'),
datamodel='not', comm=gc['default_comm']):
comm=gc['default_comm']):
"""
Sets the attributes for an lm_space class instance.
......@@ -166,16 +166,6 @@ class lm_space(point_space):
dtype = np.dtype('complex128')
self.dtype = dtype
# set datamodel
if datamodel not in ['not']:
about.warnings.cprint(
"WARNING: %s is not a recommended datamodel for lm_space."
% datamodel)
if datamodel not in LM_DISTRIBUTION_STRATEGIES:
raise ValueError(about._errors.cstring(
"ERROR: %s is not a valid datamodel" % datamodel))
self.datamodel = datamodel
self.discrete = True
self.harmonic = True
self.distances = (np.float(1),)
......@@ -185,7 +175,6 @@ class lm_space(point_space):
lmax=self.paradict['lmax'],
dim=self.get_dim(),
comm=self.comm,
datamodel=self.datamodel,
allowed_distribution_strategies=LM_DISTRIBUTION_STRATEGIES)
@property
......@@ -337,9 +326,6 @@ class lm_space(point_space):
if self.comm is not codomain.comm:
return False
if self.datamodel is not codomain.datamodel:
return False
elif isinstance(codomain, gl_space):
# lmax==mmax
# nlat==lmax+1
......@@ -400,13 +386,11 @@ class lm_space(point_space):
nlat = self.paradict['lmax'] + 1
nlon = self.paradict['lmax'] * 2 + 1
return gl_space(nlat=nlat, nlon=nlon, dtype=new_dtype,
datamodel=self.datamodel,
comm=self.comm)
elif coname == 'hp' or (coname is None and not gc['lm2gl']):
nside = (self.paradict['lmax']+1) // 3
return hp_space(nside=nside,
datamodel=self.datamodel,
comm=self.comm)
else:
......@@ -557,10 +541,10 @@ class lm_space(point_space):
raise ValueError(about._errors.cstring(
"ERROR: unsupported codomain."))
if self.datamodel != 'not':
about.warnings.cprint(
"WARNING: Field data is consolidated to all nodes for "
"external alm2map method!")
# if self.datamodel != 'not':
# about.warnings.cprint(
# "WARNING: Field data is consolidated to all nodes for "
# "external alm2map method!")
np_x = x.get_full_data()
......@@ -630,10 +614,10 @@ class lm_space(point_space):
elif sigma < 0:
raise ValueError(about._errors.cstring("ERROR: invalid sigma."))
if self.datamodel != 'not':
about.warnings.cprint(
"WARNING: Field data is consolidated to all nodes for "
"external smoothalm method!")
# if self.datamodel != 'not':
# about.warnings.cprint(
# "WARNING: Field data is consolidated to all nodes for "
# "external smoothalm method!")
np_x = x.get_full_data()
......@@ -673,10 +657,10 @@ class lm_space(point_space):
lmax = self.paradict['lmax']
mmax = self.paradict['mmax']
if self.datamodel != 'not':
about.warnings.cprint(
"WARNING: Field data is consolidated to all nodes for "
"external anaalm/alm2cl method!")
# if self.datamodel != 'not':
# about.warnings.cprint(
# "WARNING: Field data is consolidated to all nodes for "
# "external anaalm/alm2cl method!")
np_x = x.get_full_data()
......@@ -964,7 +948,7 @@ class gl_space(point_space):
"""
def __init__(self, nlat, nlon=None, dtype=np.dtype('float64'),
datamodel='not', comm=gc['default_comm']):
comm=gc['default_comm']):
"""
Sets the attributes for a gl_space class instance.
......@@ -1004,16 +988,6 @@ class gl_space(point_space):
dtype = np.dtype('float')
self.dtype = dtype
# set datamodel
if datamodel not in ['not']:
about.warnings.cprint(
"WARNING: %s is not a recommended datamodel for gl_space."
% datamodel)
if datamodel not in GL_DISTRIBUTION_STRATEGIES:
raise ValueError(about._errors.cstring(
"ERROR: %s is not a valid datamodel" % datamodel))
self.datamodel = datamodel
self.discrete = False
self.harmonic = False
self.distances = tuple(gl.vol(self.paradict['nlat'],
......@@ -1125,9 +1099,6 @@ class gl_space(point_space):
if not isinstance(codomain, space):
raise TypeError(about._errors.cstring("ERROR: invalid input."))
if self.datamodel is not codomain.datamodel:
return False
if self.comm is not codomain.comm:
return False
......@@ -1160,11 +1131,9 @@ class gl_space(point_space):
# lmax,mmax = nlat-1,nlat-1
if self.dtype == np.dtype('float32'):
return lm_space(lmax=lmax, mmax=mmax, dtype=np.complex64,
datamodel=self.datamodel,
comm=self.comm)
else:
return lm_space(lmax=lmax, mmax=mmax, dtype=np.complex128,
datamodel=self.datamodel,
comm=self.comm)
def get_random_values(self, **kwargs):
......@@ -1271,10 +1240,10 @@ class gl_space(point_space):
"""
x = self.cast(x)
if self.datamodel != 'not':
about.warnings.cprint(
"WARNING: Field data is consolidated to all nodes for "
"external alm2map method!")
# if self.datamodel != 'not':
# about.warnings.cprint(
# "WARNING: Field data is consolidated to all nodes for "
# "external alm2map method!")
np_x = x.get_full_data()
# weight
......@@ -1344,10 +1313,10 @@ class gl_space(point_space):
lmax = codomain.paradict['lmax']
mmax = codomain.paradict['mmax']
if self.datamodel != 'not':
about.warnings.cprint(
"WARNING: Field data is consolidated to all nodes for "
"external map2alm method!")
# if self.datamodel != 'not':
# about.warnings.cprint(
# "WARNING: Field data is consolidated to all nodes for "
# "external map2alm method!")
np_x = x.get_full_data()
......@@ -1396,10 +1365,10 @@ class gl_space(point_space):
# smooth
nlat = self.paradict['nlat']
if self.datamodel != 'not':
about.warnings.cprint(
"WARNING: Field data is consolidated to all nodes for "
"external smoothmap method!")
# if self.datamodel != 'not':
# about.warnings.cprint(
# "WARNING: Field data is consolidated to all nodes for "
# "external smoothmap method!")
np_x = x.get_full_data()
......@@ -1434,10 +1403,10 @@ class gl_space(point_space):
lmax = nlat - 1
mmax = nlat - 1
if self.datamodel != 'not':
about.warnings.cprint(
"WARNING: Field data is consolidated to all nodes for "
"external anafast method!")
# if self.datamodel != 'not':
# about.warnings.cprint(
# "WARNING: Field data is consolidated to all nodes for "
# "external anafast method!")
np_x = x.get_full_data()
......@@ -1657,7 +1626,7 @@ class hp_space(point_space):
An array with one element containing the pixel size.
"""
def __init__(self, nside, datamodel='not', comm=gc['default_comm']):
def __init__(self, nside, comm=gc['default_comm']):
"""
Sets the attributes for a hp_space class instance.
......@@ -1690,16 +1659,6 @@ class hp_space(point_space):
self.dtype = np.dtype('float64')
# set datamodel
if datamodel not in ['not']:
about.warnings.cprint(
"WARNING: %s is not a recommended datamodel for hp_space."
% datamodel)
if datamodel not in HP_DISTRIBUTION_STRATEGIES:
raise ValueError(about._errors.cstring(
"ERROR: %s is not a valid datamodel" % datamodel))
self.datamodel = datamodel
self.discrete = False
self.harmonic = False
self.distances = (np.float(4*np.pi / (12*self.paradict['nside']**2)),)
......@@ -1804,9 +1763,6 @@ class hp_space(point_space):
if not isinstance(codomain, space):
raise TypeError(about._errors.cstring("ERROR: invalid input."))
if self.datamodel is not codomain.datamodel:
return False
if self.comm is not codomain.comm:
return False
......@@ -1834,7 +1790,6 @@ class hp_space(point_space):
lmax = 3*self.paradict['nside'] - 1
mmax = lmax
return lm_space(lmax=lmax, mmax=mmax, dtype=np.dtype('complex128'),
datamodel=self.datamodel,
comm=self.comm)
def get_random_values(self, **kwargs):
......@@ -1952,10 +1907,11 @@ class hp_space(point_space):
raise ValueError(about._errors.cstring(
"ERROR: unsupported codomain."))
if self.datamodel != 'not':
about.warnings.cprint(
"WARNING: Field data is consolidated to all nodes for "
"external map2alm method!")
# TODO look at these kinds of checks maybe need replacement
# if self.datamodel != 'not':
# about.warnings.cprint(
# "WARNING: Field data is consolidated to all nodes for "
# "external map2alm method!")
np_x = x.get_full_data()
......@@ -2015,10 +1971,10 @@ class hp_space(point_space):
raise ValueError(about._errors.cstring("ERROR: invalid sigma."))
# smooth
if self.datamodel != 'not':
about.warnings.cprint(
"WARNING: Field data is consolidated to all nodes for "
"external smoothalm method!")
# if self.datamodel != 'not':
# about.warnings.cprint(
# "WARNING: Field data is consolidated to all nodes for "
# "external smoothalm method!")
np_x = x.get_full_data()
......@@ -2059,10 +2015,10 @@ class hp_space(point_space):
lmax = 3*nside-1
mmax = lmax
if self.datamodel != 'not':
about.warnings.cprint(
"WARNING: Field data is consolidated to all nodes for "
"external smoothalm method!")
# if self.datamodel != 'not':
# about.warnings.cprint(
# "WARNING: Field data is consolidated to all nodes for "
# "external smoothalm method!")
np_x = x.get_full_data()
......
......@@ -272,7 +272,7 @@ class space(object):
raise NotImplementedError(about._errors.cstring(
"ERROR: no generic instance method 'getitem'."))
def setitem(self, data, key):
def setitem(self, data, update, key):
raise NotImplementedError(about._errors.cstring(
"ERROR: no generic instance method 'getitem'."))
......@@ -785,7 +785,7 @@ class point_space(space):
Pixel volume of the :py:class:`point_space`, which is always 1.
"""
def __init__(self, num, dtype=np.dtype('float'), datamodel='fftw',
def __init__(self, num, dtype=np.dtype('float'),
comm=gc['default_comm']):
"""
Sets the attributes for a point_space class instance.
......@@ -818,13 +818,6 @@ class point_space(space):
"WARNING: incompatible dtype: " + str(dtype)))
self.dtype = dtype
if datamodel not in POINT_DISTRIBUTION_STRATEGIES:
about._errors.cstring("WARNING: datamodel set to default.")
self.datamodel = \
gc['default_distribution_strategy']
else:
self.datamodel = datamodel
self.comm = self._parse_comm(comm)
self.discrete = True
# self.harmonic = False
......@@ -880,7 +873,6 @@ class point_space(space):
def copy(self):
return point_space(num=self.paradict['num'],
dtype=self.dtype,
datamodel=self.datamodel,
comm=self.comm)
def getitem(self, data, key):
......@@ -1108,13 +1100,8 @@ class point_space(space):
"loss of precision!\n")
to_copy = True
# Check the distribution_strategy
if x.distribution_strategy != self.datamodel:
to_copy = True
if to_copy:
temp = x.copy_empty(dtype=dtype,
distribution_strategy=self.datamodel)
temp = x.copy_empty(dtype=dtype)
temp.set_data(to_key=(slice(None),),
data=x,
from_key=(slice(None),))
......@@ -1128,8 +1115,7 @@ class point_space(space):
else:
x = distributed_data_object(x,
global_shape=self.get_shape(),
dtype=dtype,
distribution_strategy=self.datamodel)
dtype=dtype)
# Cast the d2o
return self.cast(x, dtype=dtype)
......@@ -1327,8 +1313,7 @@ class point_space(space):
# Prepare the empty distributed_data_object
sample = distributed_data_object(
global_shape=self.get_shape(),
dtype=self.dtype,
distribution_strategy=self.datamodel)
dtype=self.dtype)
# Case 1: uniform distribution over {-1,+1}/{1,i,-1,-i}
if arg['random'] == 'pm1':
......@@ -1632,7 +1617,6 @@ class point_space(space):
string += str(type(self)) + "\n"
string += "paradict: " + str(self.paradict) + "\n"
string += 'dtype: ' + str(self.dtype) + "\n"
string += 'datamodel: ' + str(self.datamodel) + "\n"
string += 'comm: ' + self.comm.name + "\n"
string += 'discrete: ' + str(self.discrete) + "\n"
string += 'distances: ' + str(self.distances) + "\n"
......
......@@ -122,7 +122,7 @@ class rg_space(point_space):
epsilon = 0.0001 # relative precision for comparisons
def __init__(self, shape, zerocenter=False, complexity=0, distances=None,
harmonic=False, datamodel='fftw', fft_module=gc['fft_module'],
harmonic=False, fft_module=gc['fft_module'],
comm=gc['default_comm']):
"""
Sets the attributes for an rg_space class instance.
......@@ -163,14 +163,6 @@ class rg_space(point_space):
else:
self.dtype = np.dtype('complex128')
# set datamodel
if datamodel not in ['np'] + RG_DISTRIBUTION_STRATEGIES:
about.warnings.cprint("WARNING: datamodel set to default.")
self.datamodel = \
gc['default_distribution_strategy']
else:
self.datamodel = datamodel
# set volume/distances
naxes = len(self.paradict['shape'])
if distances is None:
......@@ -210,7 +202,6 @@ class rg_space(point_space):
dgrid=distances,
zerocentered=self.paradict['zerocenter'],
comm=self.comm,
datamodel=self.datamodel,
allowed_distribution_strategies=RG_DISTRIBUTION_STRATEGIES)
@property
......@@ -257,7 +248,6 @@ class rg_space(point_space):
zerocenter=self.paradict['zerocenter'],
distances=self.distances,
harmonic=self.harmonic,
datamodel=self.datamodel,
fft_module=self.fft_machine.name,
comm=self.comm)
......@@ -376,9 +366,6 @@ class rg_space(point_space):
raise TypeError(about._errors.cstring(
"ERROR: The given codomain must be a nifty rg_space."))
if self.datamodel is not codomain.datamodel:
return False
if self.comm is not codomain.comm:
return False
......@@ -482,7 +469,6 @@ class rg_space(point_space):
shape = self.paradict['shape']
distances = 1 / (np.array(self.paradict['shape']) *
np.array(self.distances))
datamodel = self.datamodel
fft_module = self.fft_machine.name
comm = self.comm
complexity = {0: 1, 1: 0, 2: 2}[self.paradict['complexity']]
......@@ -493,7 +479,6 @@ class rg_space(point_space):
complexity=complexity,
distances=distances,
harmonic=harmonic,
datamodel=datamodel,
fft_module=fft_module,
comm=comm)
return new_space
......@@ -929,8 +914,9 @@ class rg_space(point_space):
x = self.cast(x)
# if x is hermitian it remains hermitian during smoothing
if self.datamodel in RG_DISTRIBUTION_STRATEGIES:
remeber_hermitianQ = x.hermitian
# TODO look at this later
# if self.datamodel in RG_DISTRIBUTION_STRATEGIES:
remeber_hermitianQ = x.hermitian
# Define the Gaussian kernel function
gaussian = lambda x: np.exp(-2. * np.pi**2 * x**2 * sigma**2)
......
......@@ -180,19 +180,17 @@ def generate_space(name):
return space_dict[name]
def generate_space_with_size(name, num, datamodel='fftw'):
def generate_space_with_size(name, num):
space_dict = {'space': space(),
'point_space': point_space(num, datamodel=datamodel),
'rg_space': rg_space((num, num), datamodel=datamodel),
'point_space': point_space(num),
'rg_space': rg_space((num, num)),
}
if 'lm_space' in available:
space_dict['lm_space'] = lm_space(mmax=num, lmax=num,
datamodel=datamodel)
space_dict['lm_space'] = lm_space(mmax=num, lmax=num)
if 'hp_space' in available:
space_dict['hp_space'] = hp_space(num, datamodel=datamodel)
space_dict['hp_space'] = hp_space(num)
if 'gl_space' in available:
space_dict['gl_space'] = gl_space(nlat=num, nlon=num,
datamodel=datamodel)
space_dict['gl_space'] = gl_space(nlat=num, nlon=num)
return space_dict[name]
......@@ -291,7 +289,6 @@ class Test_Common_Point_Like_Space_Interface(unittest.TestCase):
assert(isinstance(s.paradict, space_paradict))
assert(isinstance(s.paradict, space_paradict))
assert(isinstance(s.dtype, np.dtype))
assert(isinstance(s.datamodel, str))
assert(isinstance(s.discrete, bool))
# assert(isinstance(s.harmonic, bool))
assert(isinstance(s.distances, tuple))
......@@ -335,14 +332,12 @@ class Test_Point_Space(unittest.TestCase):
@parameterized.expand(
itertools.product([0, 1, 10],
all_point_datatypes,
DATAMODELS['point_space']),
all_point_datatypes),
testcase_func_name=custom_name_func)
def test_successfull_init(self, num, dtype, datamodel):
p = point_space(num, dtype, datamodel)
def test_successfull_init(self, num, dtype):
p = point_space(num, dtype)
assert_equal(p.paradict['num'], num)
assert_equal(p.dtype, dtype)
assert_equal(p.datamodel, datamodel)
assert_equal(p.discrete, True)
assert_equal(p.distances, (np.float(1.),))
......@@ -368,11 +363,10 @@ class Test_Point_Space(unittest.TestCase):
###############################################################################
@parameterized.expand(
itertools.product([0, 1, 10],
DATAMODELS['point_space']),
itertools.product([0, 1, 10]),
testcase_func_name=custom_name_func)
def test_apply_scalar_function(self, num, datamodel):
s = point_space(num, datamodel=datamodel)
def test_apply_scalar_function(self, num):
s = point_space(num)
d = generate_data(s)
t = s.apply_scalar_function(d, lambda x: x**2)
assert(check_equality(s, d**2, t))
......@@ -386,22 +380,20 @@ class Test_Point_Space(unittest.TestCase):
@parameterized.expand(
itertools.product([1, 10],
unary_operations,
DATAMODELS['point_space']),
unary_operations),
testcase_func_name=custom_name_func)
def test_unary_operations(self, num, op, datamodel):
s = point_space(num, datamodel=datamodel)
def test_unary_operations(self, num, op):
s = point_space(num)
d = s.cast(np.arange(num))
s.unary_operation(d, op)
# TODO: Implement value verification
@parameterized.expand(
itertools.product([1, 10],
binary_operations,
DATAMODELS['point_space']),
binary_operations),
testcase_func_name=custom_name_func)
def test_binary_operations(self, num, op, datamodel):
s = point_space(num, datamodel=datamodel)
def test_binary_operations(self, num, op):
s = point_space(num)
d = s.cast(np.arange(num))
d2 = d[::-1]
s.binary_operation(d, d2, op)
......@@ -410,12 +402,11 @@ class Test_Point_Space(unittest.TestCase):
###############################################################################
@parameterized.expand(
itertools.product(all_point_datatypes,
DATAMODELS['point_space']),
itertools.product(all_point_datatypes),
testcase_func_name=custom_name_func)
def test_get_shape_dim(self, dtype, datamodel):
def test_get_shape_dim(self, dtype):
num = 10
s = point_space(num, dtype, datamodel=datamodel)
s = point_space(num, dtype)
assert_equal(s.get_shape(), (num,))
assert_equal(s.get_dim(), num)
......@@ -423,12 +414,11 @@ class Test_Point_Space(unittest.TestCase):
###############################################################################
@parameterized.expand(
itertools.product(all_point_datatypes,
DATAMODELS['point_space']),
itertools.product(all_point_datatypes),
testcase_func_name=custom_name_func)
def test_get_shape_dof(self, dtype, datamodel):
def test_get_shape_dof(self, dtype):
num = 10
s = point_space(num, dtype, datamodel=datamodel)
s = point_space(num, dtype)
if issubclass(dtype.type, np.complexfloating):
assert_equal(s.get_dof(), 2 * num)
......@@ -440,12 +430,11 @@ class Test_Point_Space(unittest.TestCase):
###############################################################################
@parameterized.expand(
itertools.product(all_point_datatypes,
DATAMODELS['point_space']),
itertools.product(all_point_datatypes),
testcase_func_name=custom_name_func)
def test_get_shape_vol(self, dtype, datamodel):
def test_get_shape_vol(self, dtype):
num = 10
s = point_space(num, dtype, datamodel=datamodel)
s = point_space(num, dtype)
assert_equal(s.get_vol(), 1.)
assert_equal(s.get_vol(split=True), (1.,))
......@@ -453,12 +442,11 @@ class Test_Point_Space(unittest.TestCase):
###############################################################################
@parameterized.expand(
itertools.product(all_point_datatypes,
DATAMODELS['point_space']),
itertools.product(all_point_datatypes),
testcase_func_name=custom_name_func)
def test_get_shape_metavolume(self, dtype, datamodel):
def test_get_shape_metavolume(self, dtype):
num = 10
s = point_space(num, dtype, datamodel=datamodel)
s = point_space(num, dtype)
assert_equal(s.get_meta_volume(), 10.)
assert(check_equality(s, s.get_meta_volume(split=True), s.cast(1)))
......@@ -466,93 +454,69 @@ class Test_Point_Space(unittest.TestCase):
###############################################################################
@parameterized.expand(
itertools.product(all_point_datatypes,
DATAMODELS['point_space']),
itertools.product(all_point_datatypes),
testcase_func_name=custom_name_func)
def test_cast_from_scalar(self, dtype, datamodel):
def test_cast_from_scalar(self, dtype):
num = 10
scalar = 4
s = point_space(num, dtype, datamodel=datamodel)
if datamodel == 'np':
d = (np.ones((num,)) * scalar).astype(dtype=dtype)
else:
d = distributed_data_object(scalar,
global_shape=(num,),
dtype=dtype,
distribution_strategy=datamodel)
s = point_space(num, dtype)
d = distributed_data_object(scalar,
global_shape=(num,),
dtype=dtype)