Cleanup duplicated overloads of scalar std:: functions#1765
Cleanup duplicated overloads of scalar std:: functions#1765rok-cesnovar merged 9 commits intodevelopfrom
Conversation
…gs/RELEASE_500/final)
|
Just a comment on the doxygen: I think we can use markdown backticks around variable/function names, rather than |
|
Just double checking. You mean like this:
|
|
I meant the using ` as in markdown. I've used those for the |
|
Thanks, good to know. |
Jenkins Console Log Machine informationProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010CPU: G++: Clang: |
|
The reasons all those As of C++11, there are now integral type overloads for all the primitive functions like What needs to be checked is compilability of a Stan program with |
|
Yeah, I am not sure why I thought the 2 in the below test would already check that. TEST(mathMixMatFun, asinh) {
auto f = [](const auto& x1) { return stan::math::asinh(x1); };
stan::test::expect_common_unary_vectorized(f);
stan::test::expect_unary_vectorized(f, -2.6, -1.2, -0.2, 0.5, 2, -1.2);
}This does compile fine and the TEST(mathMixMatFun, asinh_compile) {
auto x = asinh(2);
}But I think it will be simpler and cleaner to add a model to stan-dev/stan. Will do that. |
|
Cool. That's great. That test function's written with qualified calls. It'd probably be better to do something like: and let |
| @@ -45,12 +28,13 @@ struct log2_fun { | |||
| */ | |||
| template <typename T> | |||
| static inline T fun(const T& x) { | |||
There was a problem hiding this comment.
Unrelated to this PR but why are these defined as static?
There was a problem hiding this comment.
They're static so that there's no object creation/destruction at run time. Any time you can move something to a static function it's a win. You lose generality in that we can't accept an arbitrary functor, but we never need to in this application.
There was a problem hiding this comment.
Cool cool I don't see any difference between making these static vs. inline
Is this PR waiting on the above? |
|
Yep, I am working on that. |
|
Here is the related Stan PR with the test model. Its now running a test run with the Math branch set to this PR: https://jenkins.mc-stan.org/blue/organizations/jenkins/Stan/detail/PR-2899/2/pipeline |
|
Nice! I looked this over so let me check that out / when the tests pass I'll approve |
|
Great. Both windows machines are offline, so I guess it wont be soon :) Will see if there is someone in the lab to reboot our machine. Unlikely tho, as the whole uni is shut down. |
|
Upstream PR is merged, this is ready for review. |
SteveBronder
left a comment
There was a problem hiding this comment.
Looks cool beans to me! Couple optional Qs
| if (is_nan(x)) { | ||
| return x; | ||
| } else { | ||
| check_bounded("atanh", "x", x, -1, 1); | ||
| return std::atanh(x); | ||
| } | ||
| check_bounded("atanh", "x", x, -1, 1); | ||
| return std::atanh(x); |
There was a problem hiding this comment.
Just a sanity check, this was changed because the standard says below right?
If a domain error occurs, an implementation-defined value is returned (NaN where supported)
There was a problem hiding this comment.
Figure nan is a domain error
There was a problem hiding this comment.
This was changed because I feel that its an unnecessary check. An int cant be NaN as NaN is defined only for floating point numbers.
std::isnan(x) that is used underneath will just cast the int to double and do a check.
There was a problem hiding this comment.
Not a huge deal probably as I doubt many call atanh with ints.
| @@ -45,12 +28,13 @@ struct log2_fun { | |||
| */ | |||
| template <typename T> | |||
| static inline T fun(const T& x) { | |||
There was a problem hiding this comment.
Cool cool I don't see any difference between making these static vs. inline
|
|
||
| TEST(MathFunctions, expInt) { | ||
| using stan::math::exp; | ||
| using std::exp; |
There was a problem hiding this comment.
Can you double check the other function tests also have these removed?
There was a problem hiding this comment.
I did a grep of using std:: in test/unit/math/prim/fun and apart from log, sqrt, exp the only uses are with std::vector and a few tests that explicitly want std::exp, std::log or std::fabs. I think we are good.
Summary
Closes #1692 by cleaning up unnecessary int overloads.
This PR also fixes a few comments and removes functions where the only code is a call to a std function. Example:
These 2 can be removed because they are covered by
We could do this for a lot more functions, for now this just removes these simple ones.
Tests
No new tests.
Side Effects
/
Checklist
Math issue Investigate which int overloads are still needed (exp, pow, ...) #1692
Copyright holder: Rok Češnovar
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