Commit 7589b45b authored by Theo Steininger's avatar Theo Steininger
Browse files

Merge branch 'issue/12/Remove-np-support' into 'master'

Issue/12/remove np support



See merge request !6
parents d76cb478 7068b092
This diff is collapsed.
......@@ -249,7 +249,7 @@ class power_indices(object):
return result
def _compute_indices(self, nkdict):
if self.datamodel == 'np':
if self.datamodel in ['np']:
return self._compute_indices_np(nkdict)
elif self.datamodel in self.allowed_distribution_strategies:
return self._compute_indices_d2o(nkdict)
......@@ -508,7 +508,8 @@ class rg_power_indices(power_indices):
nkdict = distributed_data_object(
global_shape=shape,
dtype=np.float128,
distribution_strategy=self.datamodel)
distribution_strategy=self.datamodel,
comm=self.comm)
if self.datamodel in DISTRIBUTION_STRATEGIES['slicing']:
# get the node's individual slice of the first dimension
slice_of_first_dimension = slice(
......@@ -672,15 +673,21 @@ class lm_power_indices(power_indices):
-------
nkdict : distributed_data_object
"""
if self.datamodel == 'np':
if 'healpy' in gdi: # default
if self.datamodel != 'not':
about.warnings.cprint(
"WARNING: full kdict is temporarily stored on every node " +
"altough disribution strategy != 'not'!")
if self.datamodel in self.allowed_distribution_strategies:
if 'healpy' in gdi:
nkdict = hp.Alm.getlm(self.lmax, i=None)[0]
else:
nkdict = self._getlm()[0]
elif self.datamodel in self.allowed_distribution_strategies:
raise NotImplementedError
nkdict = distributed_data_object(
nkdict,
distribution_strategy=self.datamodel,
comm=self.comm)
else:
raise ValueError(about._errors.cstring(
"ERROR: Unsupported datamodel"))
......@@ -694,14 +701,14 @@ class lm_power_indices(power_indices):
l = index - self.lmax * m + m * (m - 1) // 2
return l, m
def _compute_indices_d2o(self, nkdict):
"""
Internal helper function which computes pindex, kindex, rho and pundex
from a given nkdict
"""
raise NotImplementedError
def _compute_indices(self, nkdict):
if self.datamodel in self.allowed_distribution_strategies:
return self._compute_indices_d2o(nkdict)
else:
raise ValueError(about._errors.cstring(
'ERROR: Datamodel is not supported.'))
def _compute_indices_np(self, nkdict):
def _compute_indices_d2o(self, nkdict):
"""
Internal helper function which computes pindex, kindex, rho and pundex
from a given nkdict
......@@ -714,7 +721,7 @@ class lm_power_indices(power_indices):
##########
# pindex #
##########
pindex = nkdict.astype(np.int, copy=True)
pindex = nkdict.copy(dtype=np.int)
#######
# rho #
......@@ -724,6 +731,6 @@ class lm_power_indices(power_indices):
##########
# pundex #
##########
pundex = self._compute_pundex_np(pindex, kindex)
pundex = self._compute_pundex_d2o(pindex, kindex)
return pindex, kindex, rho, pundex
......@@ -1161,6 +1161,9 @@ class diagonal_operator(operator):
# Set the diag-val
self.val = self.domain.cast(new_diag)
# Set the bare-val #TODO Check with Theo
self.bare = bare
# Weight if necessary
if not self.domain.discrete and bare:
self.val = self.domain.calc_weight(self.val, power=1)
......@@ -1606,7 +1609,7 @@ class diagonal_operator(operator):
class identity_operator(diagonal_operator):
def __init__(self, domain, codomain=None, bare=False):
super(diagonal_operator, self).__init__(domain=domain,
super(identity_operator, self).__init__(domain=domain,
codomain=codomain,
diag=1,
bare=bare)
......
......@@ -559,6 +559,9 @@ class rg_space(point_space):
# Parse the keyword arguments
arg = random.parse_arguments(self, **kwargs)
if arg is None:
return self.cast(0)
# Should the output be hermitianized?
hermitianizeQ = (self.paradict['complexity'] == 1)
......
......@@ -179,8 +179,8 @@ class Test_Operator_Base_Class(unittest.TestCase):
testcase_func_name=custom_name_func)
def test_successfull_init_and_methods(self, name):
op = generate_operator(name)
assert(callable(op.__set_val__))
assert(callable(op.__get_val__))
assert(callable(op.set_val))
assert(callable(op.get_val))
assert(callable(op._multiply))
assert(callable(op._adjoint_multiply))
assert(callable(op._inverse_multiply))
......@@ -199,7 +199,7 @@ class Test_Operator_Base_Class(unittest.TestCase):
assert(callable(op.diag))
assert(callable(op.det))
assert(callable(op.inverse_det))
assert(callable(op.log_et))
assert(callable(op.log_det))
assert(callable(op.tr_log))
assert(callable(op.hat))
assert(callable(op.inverse_hat))
......
......@@ -82,9 +82,9 @@ all_hp_datatypes = [np.dtype('float64')]
DATAMODELS = {}
DATAMODELS['point_space'] = ['np'] + POINT_DISTRIBUTION_STRATEGIES
DATAMODELS['rg_space'] = ['np'] + RG_DISTRIBUTION_STRATEGIES
DATAMODELS['lm_space'] = ['np'] + LM_DISTRIBUTION_STRATEGIES
DATAMODELS['gl_space'] = ['np'] + GL_DISTRIBUTION_STRATEGIES
DATAMODELS['hp_space'] = ['np'] + HP_DISTRIBUTION_STRATEGIES
DATAMODELS['lm_space'] = [] + LM_DISTRIBUTION_STRATEGIES
DATAMODELS['gl_space'] = [] + GL_DISTRIBUTION_STRATEGIES
DATAMODELS['hp_space'] = [] + HP_DISTRIBUTION_STRATEGIES
###############################################################################
......@@ -296,6 +296,7 @@ class Test_Common_Point_Like_Space_Interface(unittest.TestCase):
assert(isinstance(s.get_dof(split=True), tuple))
assert(isinstance(s.get_meta_volume(), np.float))
print(s.get_meta_volume(split=True), type(s.cast(1)))
assert(isinstance(s.get_meta_volume(split=True), type(s.cast(1))))
assert_almost_equal(
s.get_meta_volume(), s.get_meta_volume(split=True).sum(), 2)
......@@ -1022,18 +1023,22 @@ class Test_Lm_Space(unittest.TestCase):
DATAMODELS['lm_space']),
testcase_func_name=custom_name_func)
def test_successfull_init(self, lmax, mmax, dtype, datamodel):
l = lm_space(lmax, mmax=mmax, dtype=dtype, datamodel=datamodel)
assert(isinstance(l.harmonic, bool))
assert_equal(l.paradict['lmax'], lmax)
if mmax is None or mmax > lmax:
assert_equal(l.paradict['mmax'], lmax)
if datamodel in ['not']:
l = lm_space(lmax, mmax=mmax, dtype=dtype, datamodel=datamodel)
assert(isinstance(l.harmonic, bool))
assert_equal(l.paradict['lmax'], lmax)
if mmax is None or mmax > lmax:
assert_equal(l.paradict['mmax'], lmax)
else:
assert_equal(l.paradict['mmax'], mmax)
assert_equal(l.dtype, dtype)
assert_equal(l.datamodel, datamodel)
assert_equal(l.discrete, True)
assert_equal(l.harmonic, True)
assert_equal(l.distances, (np.float(1),))
else:
assert_equal(l.paradict['mmax'], mmax)
assert_equal(l.dtype, dtype)
assert_equal(l.datamodel, datamodel)
assert_equal(l.discrete, True)
assert_equal(l.harmonic, True)
assert_equal(l.distances, (np.float(1),))
with assert_raises(NotImplementedError): lm_space(lmax, mmax=mmax, dtype=dtype, datamodel=datamodel)
###############################################################################
......@@ -1076,18 +1081,21 @@ class Test_Lm_Space(unittest.TestCase):
def test_enforce_power(self, datamodel):
lmax = 17
mmax = 12
l = lm_space(lmax, mmax=mmax, datamodel=datamodel)
assert_equal(l.enforce_power(2),
np.ones(18)*2)
assert_almost_equal(
l.enforce_power(lambda x: 42 / (1 + x)**5),
np.array([ 4.20000000e+01, 1.31250000e+00, 1.72839506e-01,
4.10156250e-02, 1.34400000e-02, 5.40123457e-03,
2.49895877e-03, 1.28173828e-03, 7.11273688e-04,
4.20000000e-04, 2.60786956e-04, 1.68788580e-04,
1.13118211e-04, 7.80924615e-05, 5.53086420e-05,
4.00543213e-05, 2.95804437e-05, 2.22273027e-05]))
if datamodel in ['not']:
l = lm_space(lmax, mmax=mmax, datamodel=datamodel)
assert_equal(l.enforce_power(2),
np.ones(18)*2)
assert_almost_equal(
l.enforce_power(lambda x: 42 / (1 + x)**5),
np.array([ 4.20000000e+01, 1.31250000e+00, 1.72839506e-01,
4.10156250e-02, 1.34400000e-02, 5.40123457e-03,
2.49895877e-03, 1.28173828e-03, 7.11273688e-04,
4.20000000e-04, 2.60786956e-04, 1.68788580e-04,
1.13118211e-04, 7.80924615e-05, 5.53086420e-05,
4.00543213e-05, 2.95804437e-05, 2.22273027e-05]))
else:
with assert_raises(NotImplementedError): lm_space(lmax, mmax=mmax, datamodel=datamodel)
##############################################################################
......@@ -1096,21 +1104,24 @@ class Test_Lm_Space(unittest.TestCase):
def test_get_check_codomain(self, datamodel):
lmax = 23
mmax = 23
l = lm_space(lmax, mmax=mmax, datamodel=datamodel)
y = l.get_codomain()
assert(l.check_codomain(y))
assert(y.check_codomain(l))
if datamodel in ['not']:
l = lm_space(lmax, mmax=mmax, datamodel=datamodel)
if 'hp_space' in available:
y = l.get_codomain('hp')
assert(l.check_codomain(y))
assert(y.check_codomain(l))
if 'gl_space' in available:
y = l.get_codomain('gl')
y = l.get_codomain()
assert(l.check_codomain(y))
assert(y.check_codomain(l))
if 'hp_space' in available:
y = l.get_codomain('hp')
assert(l.check_codomain(y))
assert(y.check_codomain(l))
if 'gl_space' in available:
y = l.get_codomain('gl')
assert(l.check_codomain(y))
assert(y.check_codomain(l))
else:
with assert_raises(NotImplementedError): lm_space(lmax, mmax=mmax, datamodel=datamodel)
###############################################################################
#
......
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