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

Remove linear indexing requirements from functions #2205

Merged
merged 32 commits into from
Dec 1, 2020

Conversation

t4c1
Copy link
Contributor

@t4c1 t4c1 commented Nov 23, 2020

Summary

Modifies functions requiring linear indexing of their arguments to remove that requirement.

This reintroduces part of functionality reverted in #1982.

Tests

Expression tests are modified to use a block expression, which does not support linear indexing so the tests will fail for any function that still requires linear indexing.

Side Effects

None.

Release notes

Modified functions requiring linear indexing of their arguments to remove that requirement.

Checklist

  • Math issue Generalize matrix function signatures #1470

  • Copyright holder: Tadej Ciglarič

    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

@t4c1
Copy link
Contributor Author

t4c1 commented Nov 23, 2020

@bbbales2 You found the performance regression that lead to the revert #1982, but I did not find what exactly were you testing. Can you check that this PR does not cause a similar regression or post the code you used for the benchmark?

@t4c1 t4c1 mentioned this pull request Nov 23, 2020
5 tasks
@bbbales2
Copy link
Member

@t4c1 this revert has a math benchmark: #2147

This is the model from the July revert: https://discourse.mc-stan.org/t/cmdstan-2-24-release-candidate-now-available/16818/37 (timings further down)

@bbbales2
Copy link
Member

Also I'm not gonna complain if you implement all the functionality for #1982 :P. It would be convenient to have all these checks work on nested structures.

@t4c1
Copy link
Contributor Author

t4c1 commented Nov 24, 2020

Thanks Ben. I ran those and fixed the code, so now it is as fast as develop. It turns out elementwise_check was too big and g++ decided not to inline it.

@@ -203,7 +196,7 @@ inline void elementwise_check(const F& is_good, const char* function,
const Indexings&... indexings) {
for (size_t j = 0; j < x.size(); j++) {
elementwise_check(is_good, function, name, x[j], must_be, indexings..., "[",
j, "]");
j + 1, "]");
Copy link
Member

Choose a reason for hiding this comment

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

Why the + 1 here?

Does this have anything to do with Stan indexing by 1 or not? There's a variable for this here: https://github.com/stan-dev/math/blob/235090a31ccdabdd0d9d35bfb77ba3d4b984590f/stan/math/prim/meta/error_index.hpp

I think by default the Math library compiles as if it is indexing by 1, and you can optionally change this variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because I removed the +1 from internal::pipe_in. Yeah I can change this to instead use + error_index::value.

@stan-buildbot
Copy link
Contributor


Name Old Result New Result Ratio Performance change( 1 - new / old )
gp_pois_regr/gp_pois_regr.stan 3.55 3.57 0.99 -0.51% slower
low_dim_corr_gauss/low_dim_corr_gauss.stan 0.02 0.02 0.92 -8.27% slower
eight_schools/eight_schools.stan 0.12 0.12 0.99 -0.73% slower
gp_regr/gp_regr.stan 0.17 0.17 1.0 0.5% faster
irt_2pl/irt_2pl.stan 5.67 5.66 1.0 0.15% faster
performance.compilation 87.06 85.6 1.02 1.69% faster
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan 8.45 8.44 1.0 0.19% faster
pkpd/one_comp_mm_elim_abs.stan 29.36 29.28 1.0 0.26% faster
sir/sir.stan 134.04 127.48 1.05 4.89% faster
gp_regr/gen_gp_data.stan 0.04 0.04 0.98 -1.8% slower
low_dim_gauss_mix/low_dim_gauss_mix.stan 2.93 2.95 0.99 -0.7% slower
pkpd/sim_one_comp_mm_elim_abs.stan 0.37 0.39 0.93 -7.45% slower
arK/arK.stan 2.47 2.45 1.01 1.0% faster
arma/arma.stan 0.6 0.59 1.01 1.21% faster
garch/garch.stan 0.75 0.74 1.01 0.81% faster
Mean result: 0.995161552191

Jenkins Console Log
Blue Ocean
Commit hash: 0d5cef3


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

@t4c1 t4c1 changed the title WIP: no linear indexing requirement Remove linear indexing requirements from functions Nov 28, 2020
@t4c1
Copy link
Contributor Author

t4c1 commented Nov 28, 2020

This is ready for review.

Copy link
Member

@bbbales2 bbbales2 left a comment

Choose a reason for hiding this comment

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

Review!

@stan-buildbot
Copy link
Contributor


Name Old Result New Result Ratio Performance change( 1 - new / old )
gp_pois_regr/gp_pois_regr.stan 3.53 3.52 1.0 0.27% faster
low_dim_corr_gauss/low_dim_corr_gauss.stan 0.02 0.02 0.98 -2.22% slower
eight_schools/eight_schools.stan 0.11 0.12 0.97 -3.03% slower
gp_regr/gp_regr.stan 0.17 0.16 1.02 1.87% faster
irt_2pl/irt_2pl.stan 5.73 5.65 1.01 1.45% faster
performance.compilation 86.96 85.72 1.01 1.43% faster
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan 8.46 8.42 1.0 0.43% faster
pkpd/one_comp_mm_elim_abs.stan 30.86 28.75 1.07 6.83% faster
sir/sir.stan 137.7 127.05 1.08 7.73% faster
gp_regr/gen_gp_data.stan 0.04 0.05 0.91 -10.0% slower
low_dim_gauss_mix/low_dim_gauss_mix.stan 2.94 2.93 1.0 0.27% faster
pkpd/sim_one_comp_mm_elim_abs.stan 0.41 0.4 1.02 2.4% faster
arK/arK.stan 2.49 2.45 1.02 1.89% faster
arma/arma.stan 0.6 0.59 1.02 2.21% faster
garch/garch.stan 0.74 0.74 1.0 0.48% faster
Mean result: 1.00963060401

Jenkins Console Log
Blue Ocean
Commit hash: 0d5cef3


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 3.69 3.56 1.04 3.54% faster
low_dim_corr_gauss/low_dim_corr_gauss.stan 0.02 0.02 1.04 4.28% faster
eight_schools/eight_schools.stan 0.11 0.11 1.0 0.42% faster
gp_regr/gp_regr.stan 0.17 0.16 1.01 1.36% faster
irt_2pl/irt_2pl.stan 5.87 5.8 1.01 1.14% faster
performance.compilation 86.87 85.7 1.01 1.34% faster
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan 8.46 8.37 1.01 1.04% faster
pkpd/one_comp_mm_elim_abs.stan 30.45 28.84 1.06 5.3% faster
sir/sir.stan 132.59 126.9 1.04 4.3% faster
gp_regr/gen_gp_data.stan 0.04 0.05 0.96 -4.15% slower
low_dim_gauss_mix/low_dim_gauss_mix.stan 2.94 2.92 1.01 0.72% faster
pkpd/sim_one_comp_mm_elim_abs.stan 0.37 0.39 0.96 -4.36% slower
arK/arK.stan 2.48 2.44 1.01 1.29% faster
arma/arma.stan 0.6 0.72 0.83 -20.46% slower
garch/garch.stan 0.55 0.55 0.99 -0.54% slower
Mean result: 0.999967802476

Jenkins Console Log
Blue Ocean
Commit hash: 27b17be


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

@bbbales2
Copy link
Member

@t4c1 looks good. Will approve when tests pass

@stan-buildbot
Copy link
Contributor


Name Old Result New Result Ratio Performance change( 1 - new / old )
gp_pois_regr/gp_pois_regr.stan 3.57 3.48 1.03 2.61% faster
low_dim_corr_gauss/low_dim_corr_gauss.stan 0.02 0.02 0.97 -2.86% slower
eight_schools/eight_schools.stan 0.11 0.11 0.98 -1.63% slower
gp_regr/gp_regr.stan 0.16 0.16 1.0 0.35% faster
irt_2pl/irt_2pl.stan 5.82 5.84 1.0 -0.25% slower
performance.compilation 86.9 85.48 1.02 1.63% faster
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan 8.43 8.4 1.0 0.27% faster
pkpd/one_comp_mm_elim_abs.stan 29.03 28.64 1.01 1.35% faster
sir/sir.stan 133.35 129.81 1.03 2.66% faster
gp_regr/gen_gp_data.stan 0.04 0.05 0.99 -1.09% slower
low_dim_gauss_mix/low_dim_gauss_mix.stan 2.95 2.95 1.0 -0.03% slower
pkpd/sim_one_comp_mm_elim_abs.stan 0.38 0.4 0.97 -3.07% slower
arK/arK.stan 2.47 2.45 1.01 0.99% faster
arma/arma.stan 0.6 0.73 0.82 -21.8% slower
garch/garch.stan 0.54 0.55 0.98 -2.02% slower
Mean result: 0.987651638077

Jenkins Console Log
Blue Ocean
Commit hash: e3fbd53


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

@bbbales2 bbbales2 merged commit 9d3cd07 into stan-dev:develop Dec 1, 2020
@t4c1 t4c1 deleted the no_linear_indexing_requirement branch January 18, 2021 12:25
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.

4 participants