-
-
Notifications
You must be signed in to change notification settings - Fork 190
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
Feature: L1 and L2 norms #2636
Feature: L1 and L2 norms #2636
Conversation
…4.1 (tags/RELEASE_600/final)
Thanks for the PR @lyndond and welcome to Stan Math! Just a couple of quick changes and then I can do a full review for you. For your implementations, you don't need separate specialisations for Additionally, using the You can see an example of applying both of these approaches in the Thanks! |
…4.1 (tags/RELEASE_600/final)
Thanks @andrjohns. I just made a few edits and pushed before reading your comment so I'll make changes according to your suggestions. |
@andrjohns I followed your tips and reduced some redundancy using I noticed that the Jenkins test is failing but can't decrypt the error message. Would you be able to help me with that? |
As far as I can see the Jenkins run hasn't failed, there just isn't a machine available to run the tests at the moment. But it's in the queue and will be run once a machine frees up |
…4.1 (tags/RELEASE_600/final)
…tu2~16.04.1 (tags/RELEASE_600/final)" This reverts commit dfc9a8a.
…4.1 (tags/RELEASE_600/final)
Jenkins Console Log Machine informationProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010CPU: G++: Clang: |
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.
Thanks for this PR @lyndond, you've done a great job of picking up our frameworks and coding styles!
I've made some requests in this PR. Additionally, you'll also need to add a fwd
specialisation for these functions. The fwd
specialisation is used for forward-mode autodiff where the values and gradients are computed in the same pass, we use the variable type fvar<T>
for these, where T
can be a double
, var
, or another fvar<T>
. There's an example of how to specify the fwd
specialisation for these kinds of functions in the log_sum_exp
header, and feel free to reach out if you need any clarifications or help.
Thanks for the review so far @andrjohns. I made changes according to your suggestions and will work on the corresponding |
@andrjohns: Can't we use the primitive implementation for forward mode? There's not nearly as much efficiency savings in custom autodiff for forward mode because the arithmetic doesn't incur virtual function call overhead (pointer chasing) like in reverse mode. I was thinking there could be a way to use expression templates to select primitive or forward-mode (not reverse mode). |
Oh, and @lyndond, if it's passing mix tests, the forward mode's working, as those test everything but the double-based implementations. |
@bob-carpenter, great. The It's unclear to me whether or not the new |
Jenkins Console Log Machine informationProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010CPU: G++: Clang: |
Turns out my header guards were wrong in my forward implementations so the I'm paranoid the tests are still using the |
Fair point, I was just erring on the side of consistency between all implementations |
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.
One last request and then this is all good to go!
Thanks for sticking through these requests!
stan/math/prim/fun/norm1.hpp
Outdated
* @return L1 norm of v. | ||
*/ | ||
template <typename Container, require_container_t<Container>* = nullptr, | ||
require_not_st_var<Container>* = nullptr, |
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.
These templates can be a little stricter by specifying that they're only for arithmetic types, see the log_softmax
header for an example
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.
Cool, I changed the templates to include require_st_arithmetic<>
to match the template of log_softmax
.
Does require_st_arithmetic<>
do the job of both require_not_st_var<>
and require_not_st_fvar<>
? These are what I used to resolve ambiguity between prim
vs rev
and prim
vs fwd
, respectively.
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.
Yep, it will restrict to only matching inputs that satisfy std::is_arithmetic
Jenkins Console Log Machine informationProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010CPU: G++: Clang: |
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.
This all looks good to me! Feel free to merge once tests pass.
Thanks for your contribution and congrats on your first Math PR!
Congrats @lyndond on your first merged PR in Stan Math 🎉. Thanks! @andrjohns I think someone with elevated permission will have to merge. |
Oh right, will do that now |
Great! Thanks @rok-cesnovar @bob-carpenter & @andrjohns. I appreciate the welcoming support and look forward to contributing more in the future. |
@andrjohns where can I find unit tests for |
If there are mix tests, then there is no need for separate rev tests - the mix tests both rev, fwd and mix. If you want to run mix tests but only actually run the rev part of them, set |
I missed the |
Summary
rev/.../norm1.hpp
andrev/.../norm2.hpp
implementations.norm2()
"As noted in the issue:
Tests
dot_self
Side Effects
n/a
Release notes
n/a
Checklist
Math issue L1 and L2 norms (Euclidean and taxicab lengths) #2562
Copyright holder: Lyndon Duong
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