-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add some functions to PaddleAPI.h #1013
Changes from all commits
e3d4da2
9601c2f
8b833d5
343d997
b23d99d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -450,6 +450,8 @@ class Arguments { | |
IVector* vec) throw(RangeError); | ||
void setSlotSequenceDim(size_t idx, IVector* vec) throw(RangeError); | ||
|
||
float sumCosts() const; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PR的description里说明一下为什么需要增加这几个函数吧。加了之后能有什么好处:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM |
||
|
||
private: | ||
static Arguments* createByPaddleArgumentVector(void* ptr); | ||
void* getInternalArgumentsPtr() const; | ||
|
@@ -546,6 +548,10 @@ class Parameter { | |
ParameterConfig* getConfig(); | ||
void setValueUpdated(); | ||
|
||
bool save(const std::string& filename) const; | ||
|
||
bool load(const std::string& filename) const; | ||
|
||
size_t getSize() const; | ||
|
||
private: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,4 +57,12 @@ size_t Parameter::getID() const { return m->getPtr()->getID(); } | |
|
||
void Parameter::setValueUpdated() { m->getPtr()->setValueUpdated(); } | ||
|
||
bool Parameter::save(const std::string& filename) const { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 我之前一直迟迟没有approve这个PR的一个主要原因是,save/load(filename) 这样的methods不是一个好的设计。 首先这些methods不容易被unit test。除非我们有一个in-memory mock filesystem。但实际上我们不需要这么复杂的test facility。而且这些methods里的内容经常和网络传输methods里的内容重复——都是要 serialize/deserialize class memebers。 一个比较常见的设计是用 serialize/deserialize 来代替 save/load:
这样一来容易unit test,二来容易用于网络传输和磁盘I/O:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 非常有道理!现在的接口是不适合分布式化的,serialize/deserialize才能更方便传输。目前暴露的接口是老接口,仅仅是暴露出来,下一步提供c-api的时候可以考虑重构。 |
||
return m->getPtr()->save(filename); | ||
} | ||
|
||
bool Parameter::load(const std::string& filename) const { | ||
return m->getPtr()->load(filename); | ||
} | ||
|
||
size_t Parameter::getSize() const { return m->getPtr()->getSize(); } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.w0 | ||
*.wbias |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function names should be Camel Cased: https://google.github.io/styleguide/cppguide.html#Function_Names
是不是至少对于新加的函数,应该符合code style,这样至少提醒大家关注规范;现有的函数,可以以后写个工具重命名?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
麻烦review一下这个 baidu-adu/cpp-primer-digest#1
这个是Paddle目前的命名风格。