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

Cleanup requires with macros #1794

Merged
merged 38 commits into from
Mar 30, 2020
Merged

Cleanup requires with macros #1794

merged 38 commits into from
Mar 30, 2020

Conversation

SteveBronder
Copy link
Collaborator

@SteveBronder SteveBronder commented Mar 23, 2020

Summary

This PR cleans the requires* meta programs to be auto generated using macros. This PR should be fully backwards compatible with the current method. More importantly, the documentation for these has been cleanup up such that it's much easier to go through and look for certain types of requires.

The macros are

STAN_ADD_REQUIRE_UNARY: For validating a single type satisfies a type trait.
STAN_ADD_REQUIRE_BINARY: For type traits that require comparing two types.
Both of these have a *_INNER macro that defines requires to check the scalar_type and value_type of arbitrary types. This is more useful for binary requires where we want to check that two matrices for instance have the same value_type. These are labeled as require_vt/st_* i.e. require_vt_same<T, S>

STAN_ADD_REQUIRE_CONTAINER: For defining requires like require_eigen_t<> and require_eigen_vt<>.

Tests

All the current tests should pass. One important thing to check is the documentation via make doxygen.

Side Effects

These macros will be floating in the background, but I think they are named such that it would be hard to accidentally hit them.

Release notes

Refactoring the require_* metaprograms to reduce code duplication and increase documentation.

Checklist

  • Math issue Breakup require_generics.hpp into multiple files #1739

  • Copyright holder: Steve Bronder

    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

    • unit tests pass (to run, use: ./runTests.py test/unit)
    • header checks pass, (make test-headers)
    • dependencies checks pass, (make test-math-dependencies)
    • docs build, (make doxygen)
    • code passes the built in C++ standards checks (make cpplint)
  • the code is written in idiomatic C++ and changes are documented in the doxygen

  • the new changes are tested

@SteveBronder
Copy link
Collaborator Author

@serban-nicusor-toptal it looks like the windows machines are taking a bit? Fine with it taking a while if there are a bunch of PRs but just a heads up

@serban-nicusor-toptal
Copy link
Contributor

Hey, one machine seems down. Going to get it up now to speed up the queue. Thanks for the notice!

@stan-buildbot
Copy link
Contributor


Name Old Result New Result Ratio Performance change( 1 - new / old )
gp_pois_regr/gp_pois_regr.stan 4.82 4.91 0.98 -1.92% slower
low_dim_corr_gauss/low_dim_corr_gauss.stan 0.02 0.02 0.98 -2.52% slower
eight_schools/eight_schools.stan 0.09 0.09 1.0 0.18% faster
gp_regr/gp_regr.stan 0.22 0.22 1.0 -0.2% slower
irt_2pl/irt_2pl.stan 6.47 6.44 1.0 0.36% faster
performance.compilation 89.03 86.65 1.03 2.67% faster
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan 7.53 7.54 1.0 -0.18% slower
pkpd/one_comp_mm_elim_abs.stan 20.77 20.9 0.99 -0.66% slower
sir/sir.stan 95.89 91.13 1.05 4.96% faster
gp_regr/gen_gp_data.stan 0.05 0.05 0.99 -1.48% slower
low_dim_gauss_mix/low_dim_gauss_mix.stan 2.95 3.11 0.95 -5.49% slower
pkpd/sim_one_comp_mm_elim_abs.stan 0.31 0.31 0.99 -0.65% slower
arK/arK.stan 1.74 1.74 1.0 0.22% faster
arma/arma.stan 0.66 0.66 0.99 -0.82% slower
garch/garch.stan 0.51 0.52 0.99 -1.43% slower
Mean result: 0.995887283487

Jenkins Console Log
Blue Ocean
Commit hash: ba5a07e


Machine information ProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010

CPU:
Intel(R) Xeon(R) CPU E5-1680 v2 @ 3.00GHz

G++:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.6.0
Thread model: posix

Clang:
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.6.0
Thread model: posix

@stan-buildbot
Copy link
Contributor


Name Old Result New Result Ratio Performance change( 1 - new / old )
gp_pois_regr/gp_pois_regr.stan 4.88 5.27 0.93 -7.93% slower
low_dim_corr_gauss/low_dim_corr_gauss.stan 0.02 0.02 0.92 -8.21% slower
eight_schools/eight_schools.stan 0.09 0.09 0.97 -3.05% slower
gp_regr/gp_regr.stan 0.22 0.22 0.98 -2.42% slower
irt_2pl/irt_2pl.stan 6.5 6.69 0.97 -2.94% slower
performance.compilation 89.03 87.4 1.02 1.82% faster
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan 7.53 7.71 0.98 -2.28% slower
pkpd/one_comp_mm_elim_abs.stan 20.65 20.78 0.99 -0.67% slower
sir/sir.stan 90.9 93.68 0.97 -3.06% slower
gp_regr/gen_gp_data.stan 0.05 0.05 0.99 -1.1% slower
low_dim_gauss_mix/low_dim_gauss_mix.stan 2.95 3.05 0.97 -3.42% slower
pkpd/sim_one_comp_mm_elim_abs.stan 0.31 0.33 0.95 -4.85% slower
arK/arK.stan 1.74 1.79 0.98 -2.55% slower
arma/arma.stan 0.66 0.68 0.97 -2.88% slower
garch/garch.stan 0.51 0.53 0.97 -3.24% slower
Mean result: 0.970288060688

Jenkins Console Log
Blue Ocean
Commit hash: dfdfdba


Machine information ProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010

CPU:
Intel(R) Xeon(R) CPU E5-1680 v2 @ 3.00GHz

G++:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.6.0
Thread model: posix

Clang:
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.6.0
Thread model: posix

@SteveBronder
Copy link
Collaborator Author

@t4c1 would you have time to give this a lookover? It looks like a lot but it's mostly just moving stuff around and a good bit of docs. The only other change is that value_type and scalar_type's eigen and std vector specializations were moved to is_eigen and is_vector. I think this makes sense because you can't detect an eigen or std vector's inner types until you can detect whether you have an eigen type or std vector type.

That and I updated the code for the functions which were giving warnings on doxygen so that we could use the warnings are errors flag in doxygen. Now if anyone does not doc correctly it will error out

* @return Sum of vector entries.
*/
template <typename T>
inline fvar<T> sum(const std::vector<fvar<T>>& m) {
if (m.size() == 0) {
inline fvar<T> sum(const std::vector<fvar<T>>& v) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you rename all these variables? I don't think these have anything to do with requires. This PR is already large enough, so if you think these are needed, they should be put in a separate PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are just to fix the doxygen warnings but I can undo them

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To undo these I will need to turn off the doxygen option to promote warnings to errors that I added in this PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that is so, I am ok with leaving those in. I did not understand these are connected with docs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, what kind of warnings did renaming a few variables solve?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you already reverted those. Lets leave them for another PR.

/** \addtogroup type_trait
* @{
*/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this just moved from stan/math.hpp?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'll remove this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is now replaced with docs on each require(that are generated with macros)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this just moved from stan/math.hpp?

I meant the whole ~150 lines of docs.

@SteveBronder SteveBronder linked an issue Mar 28, 2020 that may be closed by this pull request
@stan-buildbot
Copy link
Contributor


Name Old Result New Result Ratio Performance change( 1 - new / old )
gp_pois_regr/gp_pois_regr.stan 4.9 4.95 0.99 -0.9% slower
low_dim_corr_gauss/low_dim_corr_gauss.stan 0.02 0.02 0.97 -2.92% slower
eight_schools/eight_schools.stan 0.09 0.09 1.0 0.31% faster
gp_regr/gp_regr.stan 0.22 0.22 0.98 -2.49% slower
irt_2pl/irt_2pl.stan 6.49 6.42 1.01 1.02% faster
performance.compilation 88.86 88.55 1.0 0.35% faster
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan 7.52 7.52 1.0 0.08% faster
pkpd/one_comp_mm_elim_abs.stan 21.85 20.9 1.05 4.36% faster
sir/sir.stan 94.18 90.76 1.04 3.63% faster
gp_regr/gen_gp_data.stan 0.05 0.05 0.99 -0.78% slower
low_dim_gauss_mix/low_dim_gauss_mix.stan 2.95 2.96 1.0 -0.18% slower
pkpd/sim_one_comp_mm_elim_abs.stan 0.31 0.31 0.99 -0.51% slower
arK/arK.stan 1.73 1.74 0.99 -0.68% slower
arma/arma.stan 0.66 0.66 0.99 -0.94% slower
garch/garch.stan 0.52 0.51 1.01 0.73% faster
Mean result: 1.00107751521

Jenkins Console Log
Blue Ocean
Commit hash: 70035f4


Machine information ProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010

CPU:
Intel(R) Xeon(R) CPU E5-1680 v2 @ 3.00GHz

G++:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.6.0
Thread model: posix

Clang:
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.6.0
Thread model: posix

STAN_ADD_REQUIRE_UNARY_INNER(floating_point, std::is_floating_point,
require_stan_scalar_real);
STAN_ADD_REQUIRE_UNARY(index, std::is_integral, require_stan_scalar_real);
STAN_ADD_REQUIRE_UNARY_INNER(index, std::is_integral, require_stan_scalar_real);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it is not part of this PR, but why do we have require_index for is_integral?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh I put that in there whenever I was working on stan upstream stuff, I can change this

* @return Sum of vector entries.
*/
template <typename T>
inline fvar<T> sum(const std::vector<fvar<T>>& m) {
if (m.size() == 0) {
inline fvar<T> sum(const std::vector<fvar<T>>& v) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, what kind of warnings did renaming a few variables solve?

t4c1
t4c1 previously approved these changes Mar 28, 2020
Copy link
Contributor

@t4c1 t4c1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!. Just one question

@SteveBronder
Copy link
Collaborator Author

Actually, what kind of warnings did renaming a few variables solve?

It's something weird in doxygen

stan/math/rev/fun/multiply.hpp:545: warning: argument 'm1' of command @param is not found in the argument list of stan::math::multiply(const Mat1 &A, const Mat2 &B)

…e_generics and give correct includes to other headers
@SteveBronder
Copy link
Collaborator Author

@t4c1 fyi I just went through and fixed index and some header includes rest of the stuff is just merge and a cpplint fix

675b03d

@stan-buildbot
Copy link
Contributor


Name Old Result New Result Ratio Performance change( 1 - new / old )
gp_pois_regr/gp_pois_regr.stan 4.95 4.96 1.0 -0.28% slower
low_dim_corr_gauss/low_dim_corr_gauss.stan 0.02 0.02 1.05 4.56% faster
eight_schools/eight_schools.stan 0.09 0.09 1.01 1.12% faster
gp_regr/gp_regr.stan 0.22 0.22 1.01 0.7% faster
irt_2pl/irt_2pl.stan 6.49 6.44 1.01 0.69% faster
performance.compilation 89.46 86.78 1.03 3.0% faster
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan 7.51 7.59 0.99 -1.03% slower
pkpd/one_comp_mm_elim_abs.stan 20.88 21.15 0.99 -1.3% slower
sir/sir.stan 94.01 94.05 1.0 -0.03% slower
gp_regr/gen_gp_data.stan 0.05 0.05 0.99 -0.66% slower
low_dim_gauss_mix/low_dim_gauss_mix.stan 2.96 2.95 1.0 0.23% faster
pkpd/sim_one_comp_mm_elim_abs.stan 0.32 0.32 1.0 0.32% faster
arK/arK.stan 1.78 1.74 1.03 2.48% faster
arma/arma.stan 0.66 0.66 1.0 -0.01% slower
garch/garch.stan 0.52 0.51 1.01 1.41% faster
Mean result: 1.00776504704

Jenkins Console Log
Blue Ocean
Commit hash: 878d3f4


Machine information ProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010

CPU:
Intel(R) Xeon(R) CPU E5-1680 v2 @ 3.00GHz

G++:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.6.0
Thread model: posix

Clang:
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.6.0
Thread model: posix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Breakup require_generics.hpp into multiple files
5 participants