提交 7788b460 编写于 作者: F fengjiayi

Expose VarDesc interface

上级 859dba59
......@@ -328,7 +328,31 @@ All parameter, weight, gradient are variables in Paddle.
[](BlockDesc &self, int32_t idx) { self.set_parent_idx(idx); })
.def("parent", [](BlockDesc &self) { return self.parent_idx(); });
py::class_<VarDesc>(m, "VarDesc", "");
py::class_<VarDesc>(m, "VarDesc", "")
.def(py::init<>())
.def("set_name",
[](VarDesc &self, const std::string &name) { self.set_name(name); })
.def("set_shape",
[](VarDesc &self, const std::vector<int64_t> &dims) {
LoDTensorDesc *lod_tensor_desc = self.mutable_lod_tensor();
for (const int64_t &i : dims) {
lod_tensor_desc->add_dims(i);
}
})
.def("set_data_type",
[](VarDesc &self, int type_id) {
LoDTensorDesc *lod_tensor_desc = self.mutable_lod_tensor();
lod_tensor_desc->set_data_type(static_cast<DataType>(type_id));
})
.def("shape", [](VarDesc &self) {
const LoDTensorDesc &lod_tensor_desc = self.lod_tensor();
int rank = lod_tensor_desc.dims_size();
std::vector<int64_t> res(rank);
for (int i = 0; i < rank; ++i) {
res[i] = lod_tensor_desc.dims(i);
}
return res;
});
py::class_<OpDesc>(m, "OpDesc", "");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册