diff --git a/paddle/operators/fill_zeros_like_op.cc b/paddle/operators/fill_zeros_like_op.cc index 79a0e3d7e911b728a7a96ceff573976ba2b2e37f..87f5f09ce9b29fa915e3cef559293293367c964b 100644 --- a/paddle/operators/fill_zeros_like_op.cc +++ b/paddle/operators/fill_zeros_like_op.cc @@ -13,8 +13,6 @@ See the License for the specific language governing permissions and limitations under the License. */ #include "paddle/operators/fill_zeros_like_op.h" -#include "paddle/framework/op_registry.h" -#include "paddle/framework/tensor.h" namespace paddle { namespace operators { diff --git a/paddle/operators/fill_zeros_like_op.h b/paddle/operators/fill_zeros_like_op.h index 05272964abd43bdc2bd5c3cae8b128099e1c888c..1c7c6de40279c285cc560b0d3e0aa15888990b89 100644 --- a/paddle/operators/fill_zeros_like_op.h +++ b/paddle/operators/fill_zeros_like_op.h @@ -13,9 +13,7 @@ See the License for the specific language governing permissions and limitations under the License. */ #pragma once -#include "glog/logging.h" -#include "paddle/framework/eigen.h" -#include "paddle/framework/operator.h" +#include "paddle/operators/type_alias.h" namespace paddle { namespace operators { diff --git a/paddle/pybind/CMakeLists.txt b/paddle/pybind/CMakeLists.txt index 7d0e68a8f30de609b870c81c3bdb7aee090f15d3..9bf2d6f72ea9c25919d91fe450c463bdd80c5e6d 100644 --- a/paddle/pybind/CMakeLists.txt +++ b/paddle/pybind/CMakeLists.txt @@ -1,2 +1,2 @@ cc_library(paddle_pybind SHARED SRCS pybind.cc DEPS pybind python - add_op fc_op sgd_op cross_entropy_op recurrent_network_op) + add_op fc_op sgd_op cross_entropy_op recurrent_network_op fill_zeros_like_op) diff --git a/paddle/pybind/pybind.cc b/paddle/pybind/pybind.cc index ee5f675e2512c8d167b590b6a551efd273267fb0..f2e9aa6b5d693f6b3706cd9a16fdfea1fec5ebea 100644 --- a/paddle/pybind/pybind.cc +++ b/paddle/pybind/pybind.cc @@ -37,6 +37,7 @@ USE_OP(sigmoid); USE_OP(softmax); USE_OP(rowwise_add); USE_OP_WITHOUT_KERNEL(recurrent_op); +USE_OP(fill_zeros_like); template void ExposeOperator(ClassType& m) { diff --git a/python/paddle/v2/framework/tests/CMakeLists.txt b/python/paddle/v2/framework/tests/CMakeLists.txt index cdaaa60674937c68c38656a5046bcb29f44d6c8b..4b70af68615581748605ad94aeb70ff2638f813c 100644 --- a/python/paddle/v2/framework/tests/CMakeLists.txt +++ b/python/paddle/v2/framework/tests/CMakeLists.txt @@ -13,4 +13,5 @@ add_python_test(test_framework test_sigmoid_op.py test_softmax_op.py test_rowwise_add_op.py + test_fill_zeros_like_op.py test_network.py) diff --git a/python/paddle/v2/framework/tests/test_fill_zeros_like_op.py b/python/paddle/v2/framework/tests/test_fill_zeros_like_op.py new file mode 100644 index 0000000000000000000000000000000000000000..772edf895c56c38064e2459ae2bf6586742a451b --- /dev/null +++ b/python/paddle/v2/framework/tests/test_fill_zeros_like_op.py @@ -0,0 +1,35 @@ +import unittest +import paddle.v2.framework.create_op_creation_methods as creation +import paddle.v2.framework.core as core +from op_test_util import OpTestMeta +import numpy + + +class TestFillZerosLikeOp(unittest.TestCase): + def test_fill(self): + scope = core.Scope(None) + a = scope.create_var("input") + a_tensor = a.get_tensor() + a_tensor.set_dims([546, 291]) + a_tensor.alloc_float() + a_tensor.set(numpy.random.random((546, 291)).astype("float32")) + + op = creation.op_creations.fill_zeros_like(Src="input", Dst="output") + + for out in op.outputs(): + if scope.get_var(out) is None: + scope.create_var(out).get_tensor() + + b_tensor = scope.get_var("output").get_tensor() + op.infer_shape(scope) + self.assertEqual([546, 291], b_tensor.shape()) + ctx = core.DeviceContext.cpu_context() + op.run(scope, ctx) + b_tensor_array = numpy.array(b_tensor) + for r in range(0, 546): + for c in range(0, 291): + self.assertEqual(b_tensor_array[r][c], 0.0) + + +if __name__ == '__main__': + unittest.main()