Commit 565e10ac authored by Philipp Arras's avatar Philipp Arras
Browse files

mpi-related fixes

parent 13c8fe93
...@@ -34,18 +34,21 @@ class MaskOperator(LinearOperator): ...@@ -34,18 +34,21 @@ class MaskOperator(LinearOperator):
self._target = DomainTuple.make(UnstructuredDomain(self._mask.sum())) self._target = DomainTuple.make(UnstructuredDomain(self._mask.sum()))
def data_indices(self): def data_indices(self):
return np.indices(self.domain.shape).transpose((1, 2, 0))[self._mask] if len(self.domain.shape) == 1:
return np.arange(self.domain.shape[0])[self._mask]
if len(self.domain.shape) == 2:
return np.indices(self.domain.shape).transpose((1, 2, 0))[self._mask]
def apply(self, x, mode): def apply(self, x, mode):
self._check_input(x, mode) self._check_input(x, mode)
if mode == self.TIMES: if mode == self.TIMES:
res = x.to_global_data()[self._mask] res = x.to_global_data()[self._mask]
return Field(self.target, res) return Field.from_global_data(self.target, res)
x = x.to_global_data() x = x.to_global_data()
res = np.empty(self.domain.shape, x.dtype) res = np.empty(self.domain.shape, x.dtype)
res[self._mask] = x res[self._mask] = x
res[~self._mask] = 0 res[~self._mask] = 0
return Field(self.domain, res) return Field.from_global_data(self.domain, res)
@property @property
def capability(self): def capability(self):
......
...@@ -64,10 +64,10 @@ class Consistency_Tests(unittest.TestCase): ...@@ -64,10 +64,10 @@ class Consistency_Tests(unittest.TestCase):
@expand(product(_p_spaces, [np.float64, np.complex128])) @expand(product(_p_spaces, [np.float64, np.complex128]))
def testMask(self, sp, dtype): def testMask(self, sp, dtype):
# Create mask # Create mask
f = ift.from_random('normal', sp).val f = ift.from_random('normal', sp).to_global_data()
mask = np.zeros_like(f) mask = np.zeros_like(f)
mask[f > 0] = 1 mask[f > 0] = 1
mask = ift.Field(sp, mask) mask = ift.Field.from_global_data(sp, mask)
# Test MaskOperator # Test MaskOperator
op = ift.MaskOperator(mask) op = ift.MaskOperator(mask)
ift.extra.consistency_check(op, dtype, dtype) ift.extra.consistency_check(op, dtype, dtype)
......
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