Beispiel #1
0
 def test_api_with_dygraph(self):
     with fluid.dygraph.guard():
         data = np.random.random([1, 9, 9, 4]).astype('float32')
         x = fluid.dygraph.to_variable(data)
         tril_out, triu_out = tensor.tril(x).numpy(), tensor.triu(x).numpy()
         self.assertTrue(np.allclose(tril_out, np.tril(data)))
         self.assertTrue(np.allclose(triu_out, np.triu(data)))
Beispiel #2
0
    def test_api_with_dygraph(self):
        paddle.disable_static()

        dtypes = ['float16', 'float32']
        for dtype in dtypes:
            with fluid.dygraph.guard():
                data = np.random.random([1, 9, 9, 4]).astype(dtype)
                x = fluid.dygraph.to_variable(data)
                tril_out, triu_out = tensor.tril(x).numpy(), tensor.triu(
                    x).numpy()
                self.assertTrue(np.allclose(tril_out, np.tril(data)))
                self.assertTrue(np.allclose(triu_out, np.triu(data)))
Beispiel #3
0
    def test_api(self):
        data = np.random.random([1, 9, 9, 4]).astype('float32')
        x = fluid.data(shape=[1, 9, -1, 4], dtype='float32', name='x')
        tril_out, triu_out = tensor.tril(x), tensor.triu(x)

        place = fluid.CUDAPlace(
            0) if fluid.core.is_compiled_with_cuda() else fluid.CPUPlace()
        exe = fluid.Executor(place)
        tril_out, triu_out = exe.run(
            fluid.default_main_program(),
            feed={"x": data},
            fetch_list=[tril_out, triu_out],
        )
        self.assertTrue(np.allclose(tril_out, np.tril(data)))
        self.assertTrue(np.allclose(triu_out, np.triu(data)))
    def test_api(self):
        paddle.enable_static()

        dtypes = ['float16', 'float32']
        for dtype in dtypes:
            prog = Program()
            startup_prog = Program()
            with program_guard(prog, startup_prog):
                data = np.random.random([1, 9, 9, 4]).astype(dtype)
                x = fluid.data(shape=[1, 9, -1, 4], dtype=dtype, name='x')
                tril_out, triu_out = tensor.tril(x), tensor.triu(x)

                place = fluid.NPUPlace(0)
                exe = fluid.Executor(place)
                tril_out, triu_out = exe.run(
                    fluid.default_main_program(),
                    feed={"x": data},
                    fetch_list=[tril_out, triu_out],
                )
                self.assertTrue(np.allclose(tril_out, np.tril(data)))
                self.assertTrue(np.allclose(triu_out, np.triu(data)))