-
Notifications
You must be signed in to change notification settings - Fork 23
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
WIP Indexing autograd and tests, new loss functions #47
base: master
Are you sure you want to change the base?
Conversation
include/af/autograd/Functions.hpp
Outdated
@@ -44,6 +44,8 @@ namespace af { | |||
Variable operator <=(const Variable &lhs, const double &rhs); | |||
|
|||
Variable operator !(const Variable &input); | |||
Variable select_index(const Variable &input, const Variable &idx); | |||
Variable set_index(const Variable &input, const Variable &idx, const Variable &vals); |
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.
I think lookup
and assign
are better. Or go withgather
vs scatter
like tensorflow.
src/autograd/Functions.cpp
Outdated
|
||
auto grad_func = [](std::vector<Variable> &inputs, const Variable &grad_output) { | ||
auto grad = inputs[2].array(); | ||
auto grad_mask = af::where(grad); |
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.
Why are you converting idx
into a mask and converting it back into an index again? This is making unnecessary copies.
src/autograd/Functions.cpp
Outdated
|
||
inputs[0].addGrad(Variable(grad, false)); | ||
}; | ||
return Variable(result, {input, idx, Variable(mask, false)}, grad_func); |
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.
You only need idx
or mask
. Not both.
src/autograd/Functions.cpp
Outdated
auto grad_func = [](std::vector<Variable> &inputs, const Variable &grad_output) { | ||
inputs[0].addGrad(inputs[3] * grad_output); | ||
}; | ||
return Variable(result, {input, idx, vals, Variable(mask, false)}, grad_func); |
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.
It is better to use just index and do the masking inside the grad_func. No reason to do the masking op until it is necessary.
if(PACKAGE_TESTS) | ||
enable_testing() | ||
add_subdirectory(tests) | ||
endif() |
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.
You can avoid creating a separate option PACKAGE_TESTS
. gtest automatically addes BUILD_TESTING
which you can use.
Adds new indexing functions to address #43. Theses are needed to implement Losses ans SVM from #34 and #6 those changes are next in line.
Operator overloading currently avoided in favor of new select_index () and set_index functions(). Will change to preferred solution as part of review.
Also brings in google test framework for testing. examples/autograd.cpp has been converted to (non-comprehensive) tests.