def test_default_CPU(self): paddle.enable_static() with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()): data = paddle.tril_indices(4, None, 2) exe = paddle.static.Executor(paddle.CPUPlace()) result = exe.run(feed={}, fetch_list=[data]) expected_result = np.tril_indices(4, 2) self.assertTrue(np.allclose(result, expected_result)) with fluid.dygraph.base.guard(paddle.CPUPlace()): out = paddle.tril_indices(4, None, 2) expected_result = np.tril_indices(4, 2) self.assertEqual((out.numpy() == expected_result).all(), True)
def test_dygraph(self): places = [ paddle.CPUPlace(), paddle.fluid.CUDAPlace(0) ] if fluid.core.is_compiled_with_cuda() else [paddle.CPUPlace()] for place in places: with fluid.dygraph.base.guard(place=place): out1 = paddle.tril_indices(4, 4, 2) expected_result1 = np.tril_indices(4, 2, 4) self.assertEqual((out1.numpy() == expected_result1).all(), True)
def test_static(self): places = [ paddle.CPUPlace(), paddle.fluid.CUDAPlace(0) ] if fluid.core.is_compiled_with_cuda() else [paddle.CPUPlace()] paddle.enable_static() for place in places: with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()): data1 = paddle.tril_indices(4, 4, -1) exe1 = paddle.static.Executor(place) result1 = exe1.run(feed={}, fetch_list=[data1]) expected_result1 = np.tril_indices(4, -1, 4) self.assertTrue(np.allclose(result1, expected_result1))
def test_num_columns_type_check(): out2 = paddle.tril_indices(4, -1, 2)
def test_num_rows_type_check(): out1 = paddle.tril_indices(1.0, 1, 2)
def test_num_offset_type_check(): out3 = paddle.tril_indices(4, 4, 2.0)