Skip to content

Commit efa1093

Browse files
JepsonWongphlrain
authored andcommitted
fix elementwise_floordiv_op and elementwise_mod_op (#20534)
* fix elementwise_floordiv_op and elementwise_mod_op, test=develop * fix API.spec, test=develop * fix API.spec, test=develop
1 parent 0438450 commit efa1093

File tree

3 files changed

+85
-4
lines changed

3 files changed

+85
-4
lines changed

paddle/fluid/operators/elementwise/elementwise_floordiv_op.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,22 @@ class ElementwiseFloorDivOpMaker : public ElementwiseOpMaker {
2222
protected:
2323
std::string GetName() const override { return "FloorDiv"; }
2424
std::string GetEquation() const override { return "Out = X // Y"; }
25+
26+
void AddInputX() override {
27+
AddInput("X",
28+
"(Variable), Tensor or LoDTensor of any dimensions. Its dtype "
29+
"should be int32, int64.");
30+
}
31+
32+
void AddInputY() override {
33+
AddInput("Y",
34+
"(Variable), Tensor or LoDTensor of any dimensions. Its dtype "
35+
"should be int32, int64.");
36+
}
37+
38+
std::string GetOpFuntionality() const override {
39+
return "Floor divide two tensors element-wise";
40+
}
2541
};
2642
} // namespace operators
2743
} // namespace paddle

paddle/fluid/operators/elementwise/elementwise_mod_op.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,22 @@ class ElementwiseModOpMaker : public ElementwiseOpMaker {
2222
protected:
2323
std::string GetName() const override { return "Mod"; }
2424
std::string GetEquation() const override { return "Out = X \\\\% Y"; }
25+
26+
void AddInputX() override {
27+
AddInput("X",
28+
"(Variable), Tensor or LoDTensor of any dimensions. Its dtype "
29+
"should be int32, int64.");
30+
}
31+
32+
void AddInputY() override {
33+
AddInput("Y",
34+
"(Variable), Tensor or LoDTensor of any dimensions. Its dtype "
35+
"should be int32, int64.");
36+
}
37+
38+
std::string GetOpFuntionality() const override {
39+
return "Mod two tensors element-wise";
40+
}
2541
};
2642
} // namespace operators
2743
} // namespace paddle

python/paddle/fluid/layers/nn.py

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14320,10 +14320,60 @@ def gen_data():
1432014320

1432114321

1432214322
def elementwise_mod(x, y, axis=-1, act=None, name=None):
14323+
"""
14324+
Examples:
14325+
14326+
.. code-block:: python
14327+
14328+
import paddle.fluid as fluid
14329+
import numpy as np
14330+
14331+
def gen_data():
14332+
return {
14333+
"x": np.array([10, 15, 8]).astype('int32'),
14334+
"y": np.array([3, 6, 5]).astype('int32')
14335+
}
14336+
14337+
x = fluid.data(name="x", shape=[3], dtype='int32')
14338+
y = fluid.data(name="y", shape=[3], dtype='int32')
14339+
z = fluid.layers.elementwise_mod(x, y)
14340+
14341+
place = fluid.CPUPlace()
14342+
exe = fluid.Executor(place)
14343+
z_value = exe.run(feed=gen_data(),
14344+
fetch_list=[z.name])
14345+
14346+
print(z_value) #[1, 3, 3]
14347+
"""
1432314348
return _elementwise_op(LayerHelper('elementwise_mod', **locals()))
1432414349

1432514350

1432614351
def elementwise_floordiv(x, y, axis=-1, act=None, name=None):
14352+
"""
14353+
Examples:
14354+
14355+
.. code-block:: python
14356+
14357+
import paddle.fluid as fluid
14358+
import numpy as np
14359+
14360+
def gen_data():
14361+
return {
14362+
"x": np.array([10, 15, 8]).astype('int32'),
14363+
"y": np.array([3, 7, 5]).astype('int32')
14364+
}
14365+
14366+
x = fluid.data(name="x", shape=[3], dtype='int32')
14367+
y = fluid.data(name="y", shape=[3], dtype='int32')
14368+
z = fluid.layers.elementwise_floordiv(x, y)
14369+
14370+
place = fluid.CPUPlace()
14371+
exe = fluid.Executor(place)
14372+
z_value = exe.run(feed=gen_data(),
14373+
fetch_list=[z.name])
14374+
14375+
print(z_value) #[3, 2, 1]
14376+
"""
1432714377
return _elementwise_op(LayerHelper('elementwise_floordiv', **locals()))
1432814378

1432914379

@@ -14335,6 +14385,8 @@ def elementwise_floordiv(x, y, axis=-1, act=None, name=None):
1433514385
elementwise_max,
1433614386
elementwise_pow,
1433714387
elementwise_min,
14388+
elementwise_mod,
14389+
elementwise_floordiv,
1433814390
]:
1433914391
op_proto = OpProtoHolder.instance().get_op_proto(func.__name__)
1434014392
func.__doc__ = _generate_doc_string_(
@@ -14352,10 +14404,7 @@ def elementwise_floordiv(x, y, axis=-1, act=None, name=None):
1435214404
skip_attrs_set={"x_data_format", "y_data_format", "axis"
1435314405
}) + """\n""" + str(func.__doc__)
1435414406

14355-
for func in [
14356-
elementwise_mod,
14357-
elementwise_floordiv,
14358-
]:
14407+
for func in []:
1435914408
op_proto = OpProtoHolder.instance().get_op_proto(func.__name__)
1436014409
func.__doc__ = _generate_doc_string_(
1436114410
op_proto,

0 commit comments

Comments
 (0)