def testClipOrderExecution(self): a_data = np.asfortranarray(np.random.rand(4, 8)) a = tensor(a_data, chunk_size=3) b = clip(a, 0.2, 0.8) res = self.executor.execute_tensor(b, concat=True)[0] expected = np.clip(a_data, 0.2, 0.8) np.testing.assert_allclose(res, expected) self.assertTrue(res.flags['F_CONTIGUOUS']) self.assertFalse(res.flags['C_CONTIGUOUS'])
def test_clip_order_execution(setup): a_data = np.asfortranarray(np.random.rand(4, 8)) a = tensor(a_data, chunk_size=3) b = clip(a, 0.2, 0.8) res = b.execute().fetch() expected = np.clip(a_data, 0.2, 0.8) np.testing.assert_allclose(res, expected) assert res.flags['F_CONTIGUOUS'] is True assert res.flags['C_CONTIGUOUS'] is False
def testClipExecution(self): a_data = np.arange(10) a = tensor(a_data.copy(), chunk_size=3) b = clip(a, 1, 8) res = self.executor.execute_tensor(b, concat=True)[0] expected = np.clip(a_data, 1, 8) self.assertTrue(np.array_equal(res, expected)) a = tensor(a_data.copy(), chunk_size=3) clip(a, 3, 6, out=a) res = self.executor.execute_tensor(a, concat=True)[0] expected = np.clip(a_data, 3, 6) self.assertTrue(np.array_equal(res, expected)) a = tensor(a_data.copy(), chunk_size=3) a_min_data = np.random.randint(1, 10, size=(10, )) a_max_data = np.random.randint(1, 10, size=(10, )) a_min = tensor(a_min_data) a_max = tensor(a_max_data) clip(a, a_min, a_max, out=a) res = self.executor.execute_tensor(a, concat=True)[0] expected = np.clip(a_data, a_min_data, a_max_data) self.assertTrue(np.array_equal(res, expected)) with option_context() as options: options.chunk_size = 3 a = tensor(a_data.copy(), chunk_size=3) b = clip(a, [3, 4, 1, 1, 1, 4, 4, 4, 4, 4], 8) res = self.executor.execute_tensor(b, concat=True)[0] expected = np.clip(a_data, [3, 4, 1, 1, 1, 4, 4, 4, 4, 4], 8) self.assertTrue(np.array_equal(res, expected)) # test sparse clip a_data = sps.csr_matrix([[0, 2, 8], [0, 0, -1]]) a = tensor(a_data, chunk_size=3) b_data = sps.csr_matrix([[0, 3, 0], [1, 0, -2]]) c = clip(a, b_data, 4) res = self.executor.execute_tensor(c, concat=True)[0] expected = np.clip(a_data.toarray(), b_data.toarray(), 4) self.assertTrue(np.array_equal(res.toarray(), expected))
def test_clip_execution(setup): a_data = np.arange(10) a = tensor(a_data.copy(), chunk_size=3) b = clip(a, 1, 8) res = b.execute().fetch() expected = np.clip(a_data, 1, 8) np.testing.assert_array_equal(res, expected) a = tensor(a_data.copy(), chunk_size=3) clip(a, 3, 6, out=a) res = a.execute().fetch() expected = np.clip(a_data, 3, 6) np.testing.assert_array_equal(res, expected) a = tensor(a_data.copy(), chunk_size=3) a_min_data = np.random.randint(1, 10, size=(10, )) a_max_data = np.random.randint(1, 10, size=(10, )) a_min = tensor(a_min_data) a_max = tensor(a_max_data) clip(a, a_min, a_max, out=a) res = a.execute().fetch() expected = np.clip(a_data, a_min_data, a_max_data) np.testing.assert_array_equal(res, expected) with option_context() as options: options.chunk_size = 3 a = tensor(a_data.copy(), chunk_size=3) b = clip(a, [3, 4, 1, 1, 1, 4, 4, 4, 4, 4], 8) res = b.execute().fetch() expected = np.clip(a_data, [3, 4, 1, 1, 1, 4, 4, 4, 4, 4], 8) np.testing.assert_array_equal(res, expected) # test sparse clip a_data = sps.csr_matrix([[0, 2, 8], [0, 0, -1]]) a = tensor(a_data, chunk_size=3) b_data = sps.csr_matrix([[0, 3, 0], [1, 0, -2]]) c = clip(a, b_data, 4) res = c.execute().fetch() expected = np.clip(a_data.toarray(), b_data.toarray(), 4) np.testing.assert_array_equal(res, expected)