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

Improve tests and documentation for quad_form and quad_form_sym #1698

Merged
merged 8 commits into from
Feb 13, 2020

Conversation

mcol
Copy link
Contributor

@mcol mcol commented Feb 11, 2020

Summary

This started out to be a simple clean up of the quad_form and quad_form_sym tests, but it turned into a rabbit hole. There were a few issues around those functions:

  • the prim tests were in a single file: I've now split them into one file per function
  • the mix tests for quad_form_sym were broken because their input was not symmetric: I now symmetrize the input matrix so that tests execute as expected (this also required fixing some tolerances)
  • again in that test, variable b22 was not initialized, and variable b23 was not used
  • there were no mix tests for quad_form: this is because there was no fwd version of that function, which I've now added
  • some implementations could be consolidated by better template metaprogramming
  • there was no doxygen documentation, and now all files have some.

Fixes #1695.

Tests

Added and fixed as mentioned above.

Side Effects

None.

Checklist

  • Math issue Sort out quad_form tests #1695

  • Copyright holder: Marco Colombo

    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

@stan-buildbot
Copy link
Contributor


Name Old Result New Result Ratio Performance change( 1 - new / old )
gp_pois_regr/gp_pois_regr.stan 4.93 4.91 1.0 0.43% faster
low_dim_corr_gauss/low_dim_corr_gauss.stan 0.02 0.02 0.99 -1.0% slower
eight_schools/eight_schools.stan 0.09 0.09 0.99 -1.07% slower
gp_regr/gp_regr.stan 0.22 0.22 0.99 -1.18% slower
irt_2pl/irt_2pl.stan 6.06 6.11 0.99 -0.87% slower
performance.compilation 88.42 87.09 1.02 1.5% faster
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan 7.49 7.49 1.0 -0.02% slower
pkpd/one_comp_mm_elim_abs.stan 20.87 20.8 1.0 0.3% faster
sir/sir.stan 91.82 96.67 0.95 -5.28% slower
gp_regr/gen_gp_data.stan 0.05 0.04 1.03 3.02% faster
low_dim_gauss_mix/low_dim_gauss_mix.stan 3.0 3.01 1.0 -0.38% slower
pkpd/sim_one_comp_mm_elim_abs.stan 0.32 0.33 0.98 -2.48% slower
arK/arK.stan 1.74 1.75 0.99 -0.73% slower
arma/arma.stan 0.79 0.82 0.97 -3.03% slower
garch/garch.stan 0.58 0.59 0.98 -1.94% slower
Mean result: 0.99192776448

Jenkins Console Log
Blue Ocean
Commit hash: 065a1cd


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

Copy link
Contributor

@bob-carpenter bob-carpenter left a comment

Choose a reason for hiding this comment

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

Lots of questions and some change requests.

Thanks for updating all this and all the doc!

stan/math/fwd/fun/quad_form.hpp Outdated Show resolved Hide resolved
stan/math/fwd/fun/quad_form.hpp Outdated Show resolved Hide resolved
* Compute the quadratic form B^T A B.
*
* @tparam Ta type of elements in the square matrix
* @tparam Ra number of rows in the square matrix, can be Eigen::Dynamic
Copy link
Contributor

Choose a reason for hiding this comment

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

[question]
Can these be anything other than Eigen::Dynamic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought so. In reality we can't compile if we hardcode sizes because of check_square:

In file included from test/unit/math/prim/fun/quad_form_test.cpp:1:
In file included from ./stan/math/prim.hpp:10:
In file included from ./stan/math/prim/fun.hpp:238:
./stan/math/prim/fun/quad_form.hpp:31:3: error: no matching function for call to
      'check_square'
  check_square("quad_form", "A", A);
  ^~~~~~~~~~~~
test/unit/math/prim/fun/quad_form_test.cpp:22:31: note: in instantiation of
      function template specialization 'stan::math::quad_form<5, 5, 5, 5, double>'
      requested here
  matrix_d res2 = stan::math::quad_form(A, A);
                              ^
./stan/math/prim/err/check_square.hpp:21:13: note: candidate template ignored:
      could not match -1 against 5
inline void check_square(
            ^
1 error generated.

stan/math/fwd/fun/quad_form_sym.hpp Show resolved Hide resolved
stan/math/fwd/fun/quad_form_sym.hpp Show resolved Hide resolved
@mcol
Copy link
Contributor Author

mcol commented Feb 12, 2020

I've addressed your comments as best as I could. In test/unit/math/prim/fun/quad_form_sym_test.cpp there was a duplicate test that I merged with the existing one.

Copy link
Contributor

@bob-carpenter bob-carpenter 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. Thanks for trying the fixes. There must be issues with multiply if that doesn't work, but we can take those on in a separate issue.

stan/math/fwd/fun/quad_form_sym.hpp Show resolved Hide resolved
stan/math/fwd/fun/quad_form_sym.hpp Show resolved Hide resolved
@stan-buildbot
Copy link
Contributor


Name Old Result New Result Ratio Performance change( 1 - new / old )
gp_pois_regr/gp_pois_regr.stan 4.94 4.86 1.02 1.57% faster
low_dim_corr_gauss/low_dim_corr_gauss.stan 0.02 0.02 0.98 -2.09% slower
eight_schools/eight_schools.stan 0.09 0.09 1.03 2.47% faster
gp_regr/gp_regr.stan 0.22 0.22 1.01 0.75% faster
irt_2pl/irt_2pl.stan 6.06 6.06 1.0 0.1% faster
performance.compilation 87.35 87.12 1.0 0.26% faster
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan 7.49 7.48 1.0 0.13% faster
pkpd/one_comp_mm_elim_abs.stan 21.7 20.62 1.05 5.0% faster
sir/sir.stan 89.53 90.01 0.99 -0.53% slower
gp_regr/gen_gp_data.stan 0.05 0.05 1.0 -0.47% slower
low_dim_gauss_mix/low_dim_gauss_mix.stan 3.01 3.01 1.0 -0.26% slower
pkpd/sim_one_comp_mm_elim_abs.stan 0.32 0.32 0.98 -1.75% slower
arK/arK.stan 1.75 1.73 1.01 0.95% faster
arma/arma.stan 0.8 0.79 1.01 1.36% faster
garch/garch.stan 0.58 0.58 1.0 0.24% faster
Mean result: 1.00545387515

Jenkins Console Log
Blue Ocean
Commit hash: 23eded0


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

@mcol mcol merged commit 8fbce61 into develop Feb 13, 2020
@mcol mcol deleted the cleanup/1695-quad-form branch February 13, 2020 19:20
@rok-cesnovar rok-cesnovar mentioned this pull request Feb 14, 2020
4 tasks
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.

Sort out quad_form tests
3 participants