def test_unary_execution(setup): from mars.tensor.arithmetic import UNARY_UFUNC, arccosh, invert, sin, conj _sp_unary_ufunc = {arccosh, invert, conj} _new_unary_ufunc = list(UNARY_UFUNC - _sp_unary_ufunc)[:3] def _normalize_by_sin(func1, func2, arr): return func1(abs(sin((func2(arr))))) tested = set() rs = np.random.RandomState(0) for func1, func2 in _gen_pairs(_new_unary_ufunc): raw = rs.random((8, 8, 8)) arr1 = tensor(raw, chunk_size=4) arr2 = _normalize_by_sin(func1, func2, arr1) res = arr2.execute() res_cmp = arr2.execute(fuse_enabled=False) np.testing.assert_allclose(res[0], res_cmp[0]) tested.update([func1, func2]) # make sure all functions tested assert tested == set(_new_unary_ufunc) raw = rs.randint(100, size=(8, 8, 8)) arr1 = tensor(raw, chunk_size=4) arr2 = arccosh(1 + abs(invert(arr1))) res = arr2.execute(fuse_enabled=False).fetch() res_cmp = arccosh(1 + abs(~raw)) np.testing.assert_array_almost_equal(res[0], res_cmp[0])
def testUnaryExecution(self): from mars.tensor.arithmetic import UNARY_UFUNC, arccosh, invert, sin, conj _sp_unary_ufunc = {arccosh, invert, conj} _new_unary_ufunc = list(UNARY_UFUNC - _sp_unary_ufunc) executor_numexpr = Executor() def _normalize_by_sin(func1, func2, arr): return func1(abs(sin((func2(arr))))) for i, j in itertools.permutations(range(len(_new_unary_ufunc)), 2): raw = np.random.random((8, 8, 8)) arr1 = tensor(raw, chunk_size=4) func1 = _new_unary_ufunc[i] func2 = _new_unary_ufunc[j] arr2 = _normalize_by_sin(func1, func2, arr1) res = executor_numexpr.execute_tensor(arr2, concat=True) res_cmp = self.executor.execute_tensor(arr2, concat=True) np.testing.assert_allclose(res[0], res_cmp[0]) raw = np.random.randint(100, size=(8, 8, 8)) arr1 = tensor(raw, chunk_size=4) arr2 = arccosh(1 + abs(invert(arr1))) res = executor_numexpr.execute_tensor(arr2, concat=True) res_cmp = self.executor.execute_tensor(arr2, concat=True) self.assertTrue(np.allclose(res[0], res_cmp[0]))
def testUnaryExecution(self): from mars.tensor.arithmetic import UNARY_UFUNC, arccosh, invert, sin, conj _sp_unary_ufunc = {arccosh, invert, conj} _new_unary_ufunc = list(UNARY_UFUNC - _sp_unary_ufunc) executor_numexpr = Executor() def _normalize_by_sin(func1, func2, arr): return func1(abs(sin((func2(arr))))) tested = set() for func1, func2 in self._gen_pairs(_new_unary_ufunc): raw = np.random.random((8, 8, 8)) arr1 = tensor(raw, chunk_size=4) arr2 = _normalize_by_sin(func1, func2, arr1) res = executor_numexpr.execute_tensor(arr2, concat=True) res_cmp = self.executor.execute_tensor(arr2, concat=True) np.testing.assert_allclose(res[0], res_cmp[0]) tested.update([func1, func2]) # make sure all functions tested self.assertEqual(tested, set(_new_unary_ufunc)) raw = np.random.randint(100, size=(8, 8, 8)) arr1 = tensor(raw, chunk_size=4) arr2 = arccosh(1 + abs(invert(arr1))) res = executor_numexpr.execute_tensor(arr2, concat=True) res_cmp = self.executor.execute_tensor(arr2, concat=True) self.assertTrue(np.allclose(res[0], res_cmp[0]))