예제 #1
0
    def test_name(self):
        with fluid.program_guard(fluid.Program()):
            x = fluid.data(name="x", shape=[2, 3], dtype="float32")
            y = fluid.data(name='y', shape=[2, 3], dtype='float32')

            y_1 = paddle.div(x, y, name='div_res')
            self.assertEqual(('div_res' in y_1.name), True)
예제 #2
0
 def test_dygraph(self):
     with fluid.dygraph.guard():
         np_x = np.array([2, 3, 4]).astype('float64')
         np_y = np.array([1, 5, 2]).astype('float64')
         x = fluid.dygraph.to_variable(np_x)
         y = fluid.dygraph.to_variable(np_y)
         z = paddle.div(x, y)
         np_z = z.numpy()
         z_expected = np.array([2., 0.6, 2.])
         self.assertEqual((np_z == z_expected).all(), True)
예제 #3
0
    def test_out(self):
        with fluid.program_guard(fluid.Program()):
            x = fluid.data(name="x", shape=[3], dtype="float32")
            y = fluid.data(name='y', shape=[3], dtype='float32')

            res = fluid.data(name="output", shape=[3], dtype="float32")
            y_1 = paddle.div(x, y, out=res)

            place = fluid.CPUPlace()
            exe = fluid.Executor(place)
            data1 = np.array([2, 3, 4], dtype='float32')
            data2 = np.array([1, 5, 2], dtype='float32')
            np_res, np_y_1 = exe.run(feed={'x': data1,
                                           'y': data2},
                                     fetch_list=[res, y_1])

            self.assertEqual((np_res == np_y_1).all(), True)
def l2_norm(input, axis=1):
    norm = paddle.norm(input, 2, axis, True)
    output = paddle.div(input, norm)
    return output