Skip to content

Commit 1543c4c

Browse files
authored
Fix cpplint errors of paddle/fluid/pybind and add some tests (#9694)
* cpplint test and add tesnor_py_test.cc * Update * Update
1 parent 6ba2625 commit 1543c4c

File tree

12 files changed

+291
-218
lines changed

12 files changed

+291
-218
lines changed

paddle/fluid/pybind/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ if(WITH_PYTHON)
1515
target_link_libraries(paddle_pybind rt)
1616
endif(NOT APPLE AND NOT ANDROID)
1717
endif(WITH_AMD_GPU)
18+
19+
cc_test(tensor_py_test SRCS tensor_py_test.cc DEPS python)
1820
endif(WITH_PYTHON)

paddle/fluid/pybind/const_value.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
See the License for the specific language governing permissions and
1313
limitations under the License. */
1414

15-
#include "const_value.h"
15+
#include "paddle/fluid/pybind/const_value.h"
1616
#include "paddle/fluid/framework/operator.h"
1717

1818
namespace paddle {
1919
namespace pybind {
2020

21-
void BindConstValue(pybind11::module& m) {
22-
m.def("kEmptyVarName", [] { return framework::kEmptyVarName; });
23-
m.def("kTempVarName", [] { return framework::kTempVarName; });
24-
m.def("kGradVarSuffix", [] { return framework::kGradVarSuffix; });
25-
m.def("kZeroVarSuffix", [] { return framework::kZeroVarSuffix; });
21+
void BindConstValue(pybind11::module* m) {
22+
m->def("kEmptyVarName", [] { return framework::kEmptyVarName; });
23+
m->def("kTempVarName", [] { return framework::kTempVarName; });
24+
m->def("kGradVarSuffix", [] { return framework::kGradVarSuffix; });
25+
m->def("kZeroVarSuffix", [] { return framework::kZeroVarSuffix; });
2626
}
2727

2828
} // namespace pybind

paddle/fluid/pybind/const_value.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@ distributed under the License is distributed on an "AS IS" BASIS,
1111
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
See the License for the specific language governing permissions and
1313
limitations under the License. */
14-
1514
#pragma once
15+
1616
#include <Python.h>
17+
1718
#include "paddle/fluid/platform/enforce.h"
1819
#include "pybind11/pybind11.h"
1920

20-
namespace py = pybind11;
21-
2221
namespace paddle {
2322
namespace pybind {
24-
extern void BindConstValue(pybind11::module& m);
23+
24+
void BindConstValue(pybind11::module* m);
25+
2526
} // namespace pybind
2627
} // namespace paddle

paddle/fluid/pybind/exception.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ limitations under the License. */
1717
namespace paddle {
1818
namespace pybind {
1919

20-
void BindException(pybind11::module& m) {
21-
static pybind11::exception<platform::EnforceNotMet> exc(m, "EnforceNotMet");
20+
void BindException(pybind11::module* m) {
21+
static pybind11::exception<platform::EnforceNotMet> exc(*m, "EnforceNotMet");
2222
pybind11::register_exception_translator([](std::exception_ptr p) {
2323
try {
2424
if (p) std::rethrow_exception(p);
@@ -27,7 +27,8 @@ void BindException(pybind11::module& m) {
2727
}
2828
});
2929

30-
m.def("__unittest_throw_exception__", [] { PADDLE_THROW("test exception"); });
30+
m->def("__unittest_throw_exception__",
31+
[] { PADDLE_THROW("test exception"); });
3132
}
3233

3334
} // namespace pybind

paddle/fluid/pybind/exception.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@ distributed under the License is distributed on an "AS IS" BASIS,
1111
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
See the License for the specific language governing permissions and
1313
limitations under the License. */
14-
1514
#pragma once
15+
1616
#include <Python.h>
17+
1718
#include "paddle/fluid/platform/enforce.h"
1819
#include "pybind11/pybind11.h"
20+
1921
namespace paddle {
2022
namespace pybind {
2123

22-
extern void BindException(pybind11::module& m);
24+
void BindException(pybind11::module* m);
25+
2326
} // namespace pybind
2427
} // namespace paddle

0 commit comments

Comments
 (0)