def check_op(self, op): """Check unary operation for success. Check the one- and two-arg ufunc versions as well as the method version attached to a LocalArray. """ d = Distribution.from_shape(comm=self.comm, shape=(16, 16), dist=('b', 'n')) x = localarray.ones(d) y = localarray.ones(d) with warnings.catch_warnings(): warnings.simplefilter("ignore", category=RuntimeWarning) result0 = op(x, casting='unsafe') # standard form op(x, y=y, casting='unsafe') # two-arg form assert_array_equal(result0.ndarray, y.ndarray)
def test_ones(self): size = self.comm_size nrows = size * 3 d = Distribution.from_shape(comm=self.comm, shape=(nrows, 20)) a = localarray.ones(d) expected = np.ones((nrows // size, 20)) assert_array_equal(a.ndarray, expected)
def test_slicing(self): distribution = Distribution.from_shape(self.comm, (16, 16), dist=('b', 'n')) a = ones(distribution) if self.comm.Get_rank() == 0: dd00 = {"dist_type": 'b', "size": 5, "start": 0, "stop": 3, "proc_grid_size": 2, "proc_grid_rank": 0} dd01 = {"dist_type": 'n', "size": 16} new_distribution = Distribution(self.comm, [dd00, dd01]) rvals = a.global_index.get_slice((slice(5, None), slice(None)), new_distribution=new_distribution) assert_array_equal(rvals, np.ones((3, 16))) elif self.comm.Get_rank() == 1: dd10 = {"dist_type": 'b', "size": 5, "start": 3, "stop": 5, "proc_grid_size": 2, "proc_grid_rank": 1} dd11 = {"dist_type": 'n', "size": 16} new_distribution = Distribution(self.comm, [dd10, dd11]) rvals = a.global_index.get_slice((slice(None, 10), slice(None)), new_distribution=new_distribution) assert_array_equal(rvals, np.ones((2, 16)))
def test_slicing(self): distribution = Distribution.from_shape(self.comm, (16, 16), dist=('b', 'n')) a = ones(distribution) if self.comm.Get_rank() == 0: dd00 = { "dist_type": 'b', "size": 5, "start": 0, "stop": 3, "proc_grid_size": 2, "proc_grid_rank": 0 } dd01 = {"dist_type": 'n', "size": 16} new_distribution = Distribution(self.comm, [dd00, dd01]) rvals = a.global_index.get_slice((slice(5, None), slice(None)), new_distribution=new_distribution) assert_array_equal(rvals, np.ones((3, 16))) elif self.comm.Get_rank() == 1: dd10 = { "dist_type": 'b', "size": 5, "start": 3, "stop": 5, "proc_grid_size": 2, "proc_grid_rank": 1 } dd11 = {"dist_type": 'n', "size": 16} new_distribution = Distribution(self.comm, [dd10, dd11]) rvals = a.global_index.get_slice((slice(None, 10), slice(None)), new_distribution=new_distribution) assert_array_equal(rvals, np.ones((2, 16)))