提交 62b469f8 编写于 作者: F fengjiayi

Merge branch 'feature/pybind_for_protobuf_desc' of...

Merge branch 'feature/pybind_for_protobuf_desc' of https://github.com/reyoung/Paddle into feature/pybind_for_protobuf_desc
......@@ -53,6 +53,25 @@ bool IsCompileGPU() {
#endif
}
template <typename T>
inline std::vector<T> RepeatedToVector(
const google::protobuf::RepeatedField<T> &repeated_field) {
std::vector<T> ret;
ret.reserve(repeated_field.size());
std::copy(
repeated_field.begin(), repeated_field.end(), std::back_inserter(ret));
return ret;
}
template <typename T, typename RepeatedField>
inline void VectorToRepeated(const std::vector<T> &vec,
RepeatedField *repeated_field) {
repeated_field->Reserve(vec.size());
for (auto &elem : vec) {
*repeated_field->Add() = elem;
}
}
PYBIND11_PLUGIN(core) {
py::module m("core", "C++ core of PaddlePaddle");
......@@ -381,11 +400,7 @@ All parameter, weight, gradient are variables in Paddle.
const std::string &parameter,
const std::vector<std::string> &arguments) {
var->set_parameter(parameter);
auto args = var->mutable_arguments();
args->Reserve(static_cast<int>(arguments.size()));
for (auto &arg : arguments) {
*args->Add() = arg;
}
VectorToRepeated(arguments, var->mutable_arguments());
};
auto op_desc_set_attr = [](OpDesc &desc, const std::string &name) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册