Skip to content
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
1582a36
use PYTHON_C_API in dygraph, test=develop
wanghuancoder Apr 25, 2021
46ce8b9
modify return type, test=develop
wanghuancoder Apr 25, 2021
32b597b
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
wanghuancoder Apr 25, 2021
2caa501
fix test case error, test=develop
wanghuancoder Apr 26, 2021
dd3c657
attr map, test=develop
wanghuancoder Apr 26, 2021
a760e4c
fix numpy, test=develop
wanghuancoder Apr 27, 2021
090a540
fix throw exception bug, test=develop
wanghuancoder Apr 28, 2021
372a1ff
fix convert python var to varbase, test=develop
wanghuancoder May 7, 2021
e75f09e
fix some testcase fail, test=develop
wanghuancoder May 7, 2021
046f117
modify gil lock, test=develop
wanghuancoder May 7, 2021
96314f8
modify gil lock, test=develop
wanghuancoder May 7, 2021
c149b38
numpy64 error, test=develop
wanghuancoder May 8, 2021
0024132
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
wanghuancoder May 8, 2021
36a3f7f
return None, test=develop
wanghuancoder May 8, 2021
e0df6e4
cache return NULL, test=develop
wanghuancoder May 10, 2021
bea4ea6
numpy64, test=develop
wanghuancoder May 10, 2021
690068f
refine, test=develop
wanghuancoder May 10, 2021
6878ff5
numpy, test=develop
wanghuancoder May 11, 2021
c104201
numpy, test=develop
wanghuancoder May 11, 2021
c9c143e
numpy.ndarray, test=develop
wanghuancoder May 11, 2021
cec78dc
Tensor, test=develop
wanghuancoder May 11, 2021
89be180
refine, test=develop
wanghuancoder May 14, 2021
49df08a
refine, test=develop
wanghuancoder May 17, 2021
cb895dd
refine, test=develop
wanghuancoder May 18, 2021
ac77ef6
refine, test=develop
wanghuancoder May 18, 2021
198a8a1
refine, test=develop
wanghuancoder May 20, 2021
0fe1ab9
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
wanghuancoder May 25, 2021
81034c6
modify convert_shape_to_list when convert tensor to list, test=develop
wanghuancoder May 26, 2021
e5ed284
refine convert bool, test=develop
wanghuancoder May 28, 2021
6e1fab1
solve numpy version problem, test=develop
wanghuancoder Jun 4, 2021
9f9127c
refine numpy convert, test=develop
wanghuancoder Jun 7, 2021
599cd93
refine, test=develop
wanghuancoder Jun 7, 2021
c47b6f3
Merge branch 'develop' into pythoncapi
wanghuancoder Jun 9, 2021
d968e63
convert blockdesc, test=develop
wanghuancoder Jun 10, 2021
247d251
NULL to nullptr, test=develop
wanghuancoder Jun 11, 2021
999a1c6
refine, test=develop
wanghuancoder Jun 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 22 additions & 25 deletions paddle/fluid/pybind/imperative.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ limitations under the License. */
namespace paddle {
namespace pybind {

PyTypeObject *g_VarBase_PyType = NULL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better use either camelcase(variableName) or underscores(variable_name), not combined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done,thx!


namespace py = ::pybind11;

class Layer : public imperative::Layer {
Expand Down Expand Up @@ -611,9 +613,10 @@ void BindImperative(py::module *m_ptr) {
imperative::SetCurrentTracer(tracer);
});

py::class_<imperative::VarBase, std::shared_ptr<imperative::VarBase>>(
m, "VarBase", R"DOC()DOC")
.def_static("_alive_vars", &imperative::VarBase::AliveVarNames)
py::class_<imperative::VarBase, std::shared_ptr<imperative::VarBase>> varbase(
m, "VarBase", R"DOC()DOC");
g_VarBase_PyType = (PyTypeObject *)varbase.ptr(); // NOLINT
varbase.def_static("_alive_vars", &imperative::VarBase::AliveVarNames)
.def("__init__",
[](imperative::VarBase &self) {
std::string name =
Expand Down Expand Up @@ -1405,28 +1408,22 @@ void BindImperative(py::module *m_ptr) {
&imperative::VarBase::SetOverridedStopGradient)
.def_property("persistable", &imperative::VarBase::Persistable,
&imperative::VarBase::SetPersistable)
.def_property_readonly("shape",
[](imperative::VarBase &self) {
if (self.Var().IsType<framework::LoDTensor>()) {
return framework::vectorize<int>(
self.Var()
.Get<framework::LoDTensor>()
.dims());
} else if (self.Var()
.IsType<
framework::SelectedRows>()) {
return framework::vectorize<int>(
self.Var()
.Get<framework::SelectedRows>()
.value()
.dims());
} else {
VLOG(2) << "It is meaningless to get shape of "
"variable type "
<< GetTypeName(self);
return std::vector<int>();
}
})
.def_property_readonly(
"shape",
[](imperative::VarBase &self) {
if (self.Var().IsType<framework::LoDTensor>()) {
return framework::vectorize<int>(
self.Var().Get<framework::LoDTensor>().dims());
} else if (self.Var().IsType<framework::SelectedRows>()) {
return framework::vectorize<int>(
self.Var().Get<framework::SelectedRows>().value().dims());
} else {
VLOG(2) << "It is meaningless to get shape of "
"variable type "
<< GetTypeName(self);
return std::vector<int>();
}
})
.def_property_readonly("is_leaf", &imperative::VarBase::IsLeaf,
R"DOC(
Whether a Tensor is leaf Tensor.
Expand Down
Loading