Skip to content
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

Improve const-ness of Net #1686

Merged
merged 1 commit into from
Jan 16, 2015
Merged

Improve const-ness of Net #1686

merged 1 commit into from
Jan 16, 2015

Conversation

longjon
Copy link
Contributor

@longjon longjon commented Jan 7, 2015

Net currently has a somewhat lackluster use of const. Returned references should be const; it's not okay to modify the referents. Accessors and some other functions can be const methods; it is okay to call them on const Nets.

A few changes need to be made to fix existing code. In particular std::map::operator[] is not a const method, so the somewhat more obscure find(...)->second needs to be used instead in a couple places.

(I need a few of these for a future PR, so I went ahead and took a pass over the whole Net interface.)

If you find any of this constness too intrusive, discuss.

@@ -89,7 +89,7 @@ class Net {
* @brief For an already initialized net, implicitly copies (i.e., using no
* additional memory) the pre-trained layers from another Net.
*/
void ShareTrainedLayersWith(Net* other);
void ShareTrainedLayersWith(Net* other) const;
Copy link
Contributor

Choose a reason for hiding this comment

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

This const feels wrong from a logical perspective. It clearly modifies the current network.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, I was thinking this went the other way, thanks for pointing that out. I guess there is some subtle reason why the compiler does not generate any warnings in this case. I'll push a corrected version shortly...

@jeffdonahue
Copy link
Contributor

LGTM

longjon added a commit that referenced this pull request Jan 16, 2015
@longjon longjon merged commit c24c83e into BVLC:dev Jan 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants