-
-
Notifications
You must be signed in to change notification settings - Fork 187
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
Generalise Eigen inputs to adj_jac_apply #1811
Generalise Eigen inputs to adj_jac_apply #1811
Conversation
…stable/2017-11-14)
Jenkins Console Log Machine informationProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010CPU: G++: Clang: |
Woah seven days ago my bad. Lemme look. |
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.
Do you know if there's any way to use move semantics or forwarding to speed anything up here: https://discourse.mc-stan.org/t/adj-jac-apply/5163/6 ?
@dpsimpson asked me before he did his recent pull request here if it made sense to use adj_jac_apply (which woulda made the code simpler), but it's apparent from the stuff on discourse that this might have ended up being slower than the autodiff. Is this due to unnecessary copying?
template <typename Container, | ||
require_vector_st<std::is_arithmetic, Container>...> | ||
inline auto softmax(const Container& x) { | ||
return apply_vector_unary<Container>::apply(x, [](const auto& v) { |
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 don't think it makes sense to extend softmax to work on anything other than a stan vector. We only abuse the array/vector stuff in the distributions.
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.
That's a good call, will revert
Forwarding could be a good idea here. I might close this for now and do some testing, see what I can do |
Summary
This pull extends
adj_jac_apply
to take Eigen inputs other thanEigen::Matrix<T, R, C>
. This allows for use withEigen::Array
, Eigen expressions, andEigen::Map
. This is demonstrated by extending the currentsoftmax
function with theapply_vector_unary
framework to takestd::vector<>
(andstd::vector<std::vector<>>
) inputs viaEigen::Map
.I also combined any functions that were separately defined for ````double
and
int``` inputsTests
Expanded testing of the
softmax
functionSide Effects
N/A
Release notes
adj_jac_apply
framework generalised to take any Eigen types as inputsChecklist
Math issue Generalise Eigen inputs for adj_jac_apply #1808
Copyright holder: Andrew Johnson
The copyright holder is typically you or your assignee, such as a university or company. By submitting this pull request, the copyright holder is agreeing to the license the submitted work under the following licenses:
- Code: BSD 3-clause (https://opensource.org/licenses/BSD-3-Clause)
- Documentation: CC-BY 4.0 (https://creativecommons.org/licenses/by/4.0/)
the basic tests are passing
./runTests.py test/unit
)make test-headers
)make test-math-dependencies
)make doxygen
)make cpplint
)the code is written in idiomatic C++ and changes are documented in the doxygen
the new changes are tested