未验证 提交 ca97d6ac 编写于 作者: M mamingjie-China 提交者: GitHub

fix the doc in elementwise_add elementwise_sub elementwise_mul elementwise_div (#1762)

Add the override function in the elementwise ops
上级 4f93ae3d
...@@ -61,11 +61,12 @@ elementwise_add ...@@ -61,11 +61,12 @@ elementwise_add
x = fluid.layers.data(name="x", shape=[3], dtype='float32') x = fluid.layers.data(name="x", shape=[3], dtype='float32')
y = fluid.layers.data(name="y", shape=[3], dtype='float32') y = fluid.layers.data(name="y", shape=[3], dtype='float32')
z = fluid.layers.elementwise_add(x, y) z = fluid.layers.elementwise_add(x, y)
# z = x + y
place = fluid.CPUPlace() place = fluid.CPUPlace()
exe = fluid.Executor(place) exe = fluid.Executor(place)
z_value = exe.run(feed=gen_data(), z_value = exe.run(feed=gen_data(),
fetch_list=[z.name]) fetch_list=[z.name])
print(z_value) #[3., 8., 6.] print(z_value) # [3., 8., 6.]
**代码示例 2** **代码示例 2**
...@@ -81,6 +82,7 @@ elementwise_add ...@@ -81,6 +82,7 @@ elementwise_add
x = fluid.layers.data(name="x", shape=[2,3,4,5], dtype='float32') x = fluid.layers.data(name="x", shape=[2,3,4,5], dtype='float32')
y = fluid.layers.data(name="y", shape=[3,4], dtype='float32') y = fluid.layers.data(name="y", shape=[3,4], dtype='float32')
z = fluid.layers.elementwise_add(x, y, axis=1) z = fluid.layers.elementwise_add(x, y, axis=1)
# z = x + y
place = fluid.CPUPlace() place = fluid.CPUPlace()
exe = fluid.Executor(place) exe = fluid.Executor(place)
z_value = exe.run(feed=gen_data(), z_value = exe.run(feed=gen_data(),
...@@ -100,6 +102,7 @@ elementwise_add ...@@ -100,6 +102,7 @@ elementwise_add
} }
x = fluid.layers.data(name="x", shape=[2,3,4,5], dtype='float32') x = fluid.layers.data(name="x", shape=[2,3,4,5], dtype='float32')
y = fluid.layers.data(name="y", shape=[3,4], dtype='float32') y = fluid.layers.data(name="y", shape=[3,4], dtype='float32')
# z = x + y
z = fluid.layers.elementwise_add(x, y, axis=3) z = fluid.layers.elementwise_add(x, y, axis=3)
place = fluid.CPUPlace() place = fluid.CPUPlace()
exe = fluid.Executor(place) exe = fluid.Executor(place)
......
...@@ -61,11 +61,12 @@ elementwise_div ...@@ -61,11 +61,12 @@ elementwise_div
x = fluid.layers.data(name="x", shape=[3], dtype='float32') x = fluid.layers.data(name="x", shape=[3], dtype='float32')
y = fluid.layers.data(name="y", shape=[3], dtype='float32') y = fluid.layers.data(name="y", shape=[3], dtype='float32')
z = fluid.layers.elementwise_div(x, y) z = fluid.layers.elementwise_div(x, y)
# z = x / y
place = fluid.CPUPlace() place = fluid.CPUPlace()
exe = fluid.Executor(place) exe = fluid.Executor(place)
z_value = exe.run(feed=gen_data(), z_value = exe.run(feed=gen_data(),
fetch_list=[z.name]) fetch_list=[z.name])
print(z_value) #[2., 0.6, 2.] print(z_value) # [2., 0.6, 2.]
**代码示例 2** **代码示例 2**
...@@ -81,6 +82,7 @@ elementwise_div ...@@ -81,6 +82,7 @@ elementwise_div
x = fluid.layers.data(name="x", shape=[2,3,4,5], dtype='float32') x = fluid.layers.data(name="x", shape=[2,3,4,5], dtype='float32')
y = fluid.layers.data(name="y", shape=[3,4], dtype='float32') y = fluid.layers.data(name="y", shape=[3,4], dtype='float32')
z = fluid.layers.elementwise_div(x, y, axis=1) z = fluid.layers.elementwise_div(x, y, axis=1)
# z = x / y
place = fluid.CPUPlace() place = fluid.CPUPlace()
exe = fluid.Executor(place) exe = fluid.Executor(place)
z_value = exe.run(feed=gen_data(), z_value = exe.run(feed=gen_data(),
...@@ -101,6 +103,7 @@ elementwise_div ...@@ -101,6 +103,7 @@ elementwise_div
x = fluid.layers.data(name="x", shape=[2,3,4,5], dtype='float32') x = fluid.layers.data(name="x", shape=[2,3,4,5], dtype='float32')
y = fluid.layers.data(name="y", shape=[3,4], dtype='float32') y = fluid.layers.data(name="y", shape=[3,4], dtype='float32')
z = fluid.layers.elementwise_div(x, y, axis=3) z = fluid.layers.elementwise_div(x, y, axis=3)
# z = x / y
place = fluid.CPUPlace() place = fluid.CPUPlace()
exe = fluid.Executor(place) exe = fluid.Executor(place)
z_value = exe.run(feed=gen_data(), z_value = exe.run(feed=gen_data(),
......
...@@ -61,11 +61,12 @@ elementwise_mul ...@@ -61,11 +61,12 @@ elementwise_mul
x = fluid.layers.data(name="x", shape=[3], dtype='float32') x = fluid.layers.data(name="x", shape=[3], dtype='float32')
y = fluid.layers.data(name="y", shape=[3], dtype='float32') y = fluid.layers.data(name="y", shape=[3], dtype='float32')
z = fluid.layers.elementwise_mul(x, y) z = fluid.layers.elementwise_mul(x, y)
# z = x * y
place = fluid.CPUPlace() place = fluid.CPUPlace()
exe = fluid.Executor(place) exe = fluid.Executor(place)
z_value = exe.run(feed=gen_data(), z_value = exe.run(feed=gen_data(),
fetch_list=[z.name]) fetch_list=[z.name])
print(z_value) #[2., 15., 8.] print(z_value) # [2., 15., 8.]
**代码示例 2** **代码示例 2**
...@@ -81,6 +82,7 @@ elementwise_mul ...@@ -81,6 +82,7 @@ elementwise_mul
x = fluid.layers.data(name="x", shape=[2,3,4,5], dtype='float32') x = fluid.layers.data(name="x", shape=[2,3,4,5], dtype='float32')
y = fluid.layers.data(name="y", shape=[3,4], dtype='float32') y = fluid.layers.data(name="y", shape=[3,4], dtype='float32')
z = fluid.layers.elementwise_mul(x, y, axis=1) z = fluid.layers.elementwise_mul(x, y, axis=1)
# z = x * y
place = fluid.CPUPlace() place = fluid.CPUPlace()
exe = fluid.Executor(place) exe = fluid.Executor(place)
z_value = exe.run(feed=gen_data(), z_value = exe.run(feed=gen_data(),
...@@ -101,6 +103,7 @@ elementwise_mul ...@@ -101,6 +103,7 @@ elementwise_mul
x = fluid.layers.data(name="x", shape=[2,3,4,5], dtype='float32') x = fluid.layers.data(name="x", shape=[2,3,4,5], dtype='float32')
y = fluid.layers.data(name="y", shape=[3,4], dtype='float32') y = fluid.layers.data(name="y", shape=[3,4], dtype='float32')
z = fluid.layers.elementwise_mul(x, y, axis=3) z = fluid.layers.elementwise_mul(x, y, axis=3)
# z = x * y
place = fluid.CPUPlace() place = fluid.CPUPlace()
exe = fluid.Executor(place) exe = fluid.Executor(place)
z_value = exe.run(feed=gen_data(), z_value = exe.run(feed=gen_data(),
......
...@@ -61,11 +61,12 @@ elementwise_sub ...@@ -61,11 +61,12 @@ elementwise_sub
x = fluid.layers.data(name="x", shape=[3], dtype='float32') x = fluid.layers.data(name="x", shape=[3], dtype='float32')
y = fluid.layers.data(name="y", shape=[3], dtype='float32') y = fluid.layers.data(name="y", shape=[3], dtype='float32')
z = fluid.layers.elementwise_sub(x, y) z = fluid.layers.elementwise_sub(x, y)
# z = x - y
place = fluid.CPUPlace() place = fluid.CPUPlace()
exe = fluid.Executor(place) exe = fluid.Executor(place)
z_value = exe.run(feed=gen_data(), z_value = exe.run(feed=gen_data(),
fetch_list=[z.name]) fetch_list=[z.name])
print(z_value) #[1., -2., 2.] print(z_value) # [1., -2., 2.]
**代码示例 2** **代码示例 2**
...@@ -81,6 +82,7 @@ elementwise_sub ...@@ -81,6 +82,7 @@ elementwise_sub
x = fluid.layers.data(name="x", shape=[2,3,4,5], dtype='float32') x = fluid.layers.data(name="x", shape=[2,3,4,5], dtype='float32')
y = fluid.layers.data(name="y", shape=[3,4], dtype='float32') y = fluid.layers.data(name="y", shape=[3,4], dtype='float32')
z = fluid.layers.elementwise_sub(x, y, axis=1) z = fluid.layers.elementwise_sub(x, y, axis=1)
# z = x - y
place = fluid.CPUPlace() place = fluid.CPUPlace()
exe = fluid.Executor(place) exe = fluid.Executor(place)
z_value = exe.run(feed=gen_data(), z_value = exe.run(feed=gen_data(),
...@@ -101,6 +103,7 @@ elementwise_sub ...@@ -101,6 +103,7 @@ elementwise_sub
x = fluid.layers.data(name="x", shape=[2,3,4,5], dtype='float32') x = fluid.layers.data(name="x", shape=[2,3,4,5], dtype='float32')
y = fluid.layers.data(name="y", shape=[3,4], dtype='float32') y = fluid.layers.data(name="y", shape=[3,4], dtype='float32')
z = fluid.layers.elementwise_sub(x, y, axis=3) z = fluid.layers.elementwise_sub(x, y, axis=3)
# z = x - y
place = fluid.CPUPlace() place = fluid.CPUPlace()
exe = fluid.Executor(place) exe = fluid.Executor(place)
z_value = exe.run(feed=gen_data(), z_value = exe.run(feed=gen_data(),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册