def testTrilExecution(self): a = arange(24, chunk_size=2).reshape(2, 3, 4) t = tril(a) res = self.executor.execute_tensor(t, concat=True)[0] expected = np.tril(np.arange(24).reshape(2, 3, 4)) np.testing.assert_equal(res, expected) t = tril(a, k=1) res = self.executor.execute_tensor(t, concat=True)[0] expected = np.tril(np.arange(24).reshape(2, 3, 4), k=1) np.testing.assert_equal(res, expected) t = tril(a, k=2) res = self.executor.execute_tensor(t, concat=True)[0] expected = np.tril(np.arange(24).reshape(2, 3, 4), k=2) np.testing.assert_equal(res, expected) t = tril(a, k=-1) res = self.executor.execute_tensor(t, concat=True)[0] expected = np.tril(np.arange(24).reshape(2, 3, 4), k=-1) np.testing.assert_equal(res, expected) t = tril(a, k=-2) res = self.executor.execute_tensor(t, concat=True)[0] expected = np.tril(np.arange(24).reshape(2, 3, 4), k=-2) np.testing.assert_equal(res, expected) a = arange(12, chunk_size=2).reshape(3, 4).tosparse() t = tril(a) res = self.executor.execute_tensor(t, concat=True)[0] expected = np.tril(np.arange(12).reshape(3, 4)) self.assertIsInstance(res, SparseNDArray) np.testing.assert_equal(res, expected) t = tril(a, k=1) res = self.executor.execute_tensor(t, concat=True)[0] expected = np.tril(np.arange(12).reshape(3, 4), k=1) self.assertIsInstance(res, SparseNDArray) np.testing.assert_equal(res, expected) t = tril(a, k=2) res = self.executor.execute_tensor(t, concat=True)[0] expected = np.tril(np.arange(12).reshape(3, 4), k=2) self.assertIsInstance(res, SparseNDArray) np.testing.assert_equal(res, expected) t = tril(a, k=-1) res = self.executor.execute_tensor(t, concat=True)[0] expected = np.tril(np.arange(12).reshape(3, 4), k=-1) self.assertIsInstance(res, SparseNDArray) np.testing.assert_equal(res, expected) t = tril(a, k=-2) res = self.executor.execute_tensor(t, concat=True)[0] expected = np.tril(np.arange(12).reshape(3, 4), k=-2) self.assertIsInstance(res, SparseNDArray) np.testing.assert_equal(res, expected)
def test_tril_execution(setup): a = arange(24, chunk_size=2).reshape(2, 3, 4) t = tril(a) res = t.execute().fetch() expected = np.tril(np.arange(24).reshape(2, 3, 4)) np.testing.assert_equal(res, expected) t = tril(a, k=1) res = t.execute().fetch() expected = np.tril(np.arange(24).reshape(2, 3, 4), k=1) np.testing.assert_equal(res, expected) t = tril(a, k=2) res = t.execute().fetch() expected = np.tril(np.arange(24).reshape(2, 3, 4), k=2) np.testing.assert_equal(res, expected) t = tril(a, k=-1) res = t.execute().fetch() expected = np.tril(np.arange(24).reshape(2, 3, 4), k=-1) np.testing.assert_equal(res, expected) t = tril(a, k=-2) res = t.execute().fetch() expected = np.tril(np.arange(24).reshape(2, 3, 4), k=-2) np.testing.assert_equal(res, expected) a = arange(12, chunk_size=2).reshape(3, 4).tosparse() t = tril(a) res = t.execute().fetch() expected = np.tril(np.arange(12).reshape(3, 4)) assert isinstance(res, SparseNDArray) np.testing.assert_equal(res, expected) t = tril(a, k=1) res = t.execute().fetch() expected = np.tril(np.arange(12).reshape(3, 4), k=1) assert isinstance(res, SparseNDArray) np.testing.assert_equal(res, expected) t = tril(a, k=2) res = t.execute().fetch() expected = np.tril(np.arange(12).reshape(3, 4), k=2) assert isinstance(res, SparseNDArray) np.testing.assert_equal(res, expected) t = tril(a, k=-1) res = t.execute().fetch() expected = np.tril(np.arange(12).reshape(3, 4), k=-1) assert isinstance(res, SparseNDArray) np.testing.assert_equal(res, expected) t = tril(a, k=-2) res = t.execute().fetch() expected = np.tril(np.arange(12).reshape(3, 4), k=-2) assert isinstance(res, SparseNDArray) np.testing.assert_equal(res, expected)