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

[python] Changes definition of Variable comparison and hash #450

merged 3 commits into from May 31, 2019


None yet
2 participants
Copy link

commented May 31, 2019

This PR changes the definition of Variable comparison operators (== and !=, i.e. __eq__) and hash function (__hash__).

Previous definition was comparison c++ pointer addresses of two CgVariable s., while this version compares C++ pointer addresses of nbla::Variable of two CgVariables.

Also, given this change, behavior of get_parameter_or_create is changed so that it always returns an unliked Variable. The unlinked one shares underlying C++ nbla::Variable of the Variable, so the comparison and hash evaluation (used in Python hash types set and dict ) operation behaves as if they are the same object. This enables you to safely change the need_grad attribute in a Variable obtained by get_parameter_or_create while keeping the attributes in a Variable registered in a global parameter scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.