Skip to content

Conversation

@peterwicksstringfield
Copy link
Contributor

@peterwicksstringfield peterwicksstringfield commented Mar 24, 2020

Summary

Allow check_not_nan and friends to work on nested containers. The next PR will eliminate a bunch of boilerplate loops.

These functions now operate on nested containers:

  • check_not_nan
  • check_nonnegative
  • check_positive
  • check_finite
  • check_positive_finite
  • is_not_nan
  • is_nonnegative
  • is_positive
  • is_scal_finite
  • is_positive_finite

Adds new functions is_nonnegative and is_positive_finite. This is part of #50, but it fits in with this PR really well.

Fix a bug where check_positive("someFunction", "x", 0u) would not throw a domain_error.

Improve the error messages for csr_u_to_z when called with out of range indices.

Release Notes

Features:

New functions is_nonnegative and is_positive_finite to parallel check_nonnegative and check_positive_finite. They signal failure by returning false instead of by throwing std::domain_error.

Functions check_not_nan, check_nonnegative, check_positive, check_finite, check_positive_finite, is_not_nan, is_nonnegative, is_positive, is_scal_finite, and is_positive_finite now operate on nested containers.

Clearer error messages when csr_u_to_z is called with out of range indices.

check_positive now throws domain error when given an unsigned 0.

Tests

Tests for (check|is)_(nonnegative|positive) at 0.

Tests for the new functions is_nonnegative and is_positive_finite.

Tests to ensure that the vectorization is working.

Update some hardcoded error messages in other tests.

Fix the tests for csr_u_to_z.

Side Effects

Changes the format of some error messages.
Old:

function: y[1] is nan, but must not be nan!

New:

function: y[row=1, col=1] is nan, but must not be nan!

Where y is a matrix that contains a nan.

Release notes

New functions is_nonnegative and is_positive_finite to parallel check_nonnegative and check_positive_finite. They signal failure by returning false instead of by throwing std::domain_error.

Functions check_not_nan, check_nonnegative, check_positive, check_finite, check_positive_finite, is_not_nan, is_nonnegative, is_positive, is_scal_finite, and is_positive_finite now operate on nested containers.

Clearer error messages when csr_u_to_z is called with out of range indices.

check_positive now throws domain error when given an unsigned 0.

Checklist

peterwicksstringfield and others added 3 commits March 24, 2020 09:31
Implement is_nonnegative and is_positive_finite.

Fix error behavior for csr_u_to_z with out of range indices.

Fix check_positive at 0. 0 is not positive.
struct finite<Eigen::Matrix<T, R, C>, true> {
static void check(const char* function, const char* name,
const Eigen::Matrix<T, R, C>& y) {
if (!value_of(y).allFinite()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We want this allFinite call I think. (It does need to be value_of_rec(y).) This gives Eigen a chance to do something clever. See also: #1005. I'm not really sure what to do here?

Copy link
Member

Choose a reason for hiding this comment

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

@peterwicksstringfield, are you suggesting this should be specialized for Eigen types? That would make sense to me. Especially if we could have a microbenchmark showing the difference in performance.

@stan-buildbot
Copy link
Contributor


Name Old Result New Result Ratio Performance change( 1 - new / old )
gp_pois_regr/gp_pois_regr.stan 4.91 4.88 1.01 0.63% faster
low_dim_corr_gauss/low_dim_corr_gauss.stan 0.02 0.02 0.99 -1.47% slower
eight_schools/eight_schools.stan 0.09 0.09 1.0 -0.01% slower
gp_regr/gp_regr.stan 0.22 0.22 0.98 -2.33% slower
irt_2pl/irt_2pl.stan 6.47 6.45 1.0 0.21% faster
performance.compilation 87.86 87.09 1.01 0.87% faster
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan 7.52 8.15 0.92 -8.4% slower
pkpd/one_comp_mm_elim_abs.stan 21.01 20.82 1.01 0.87% faster
sir/sir.stan 96.91 99.44 0.97 -2.61% slower
gp_regr/gen_gp_data.stan 0.05 0.05 0.99 -1.39% slower
low_dim_gauss_mix/low_dim_gauss_mix.stan 2.95 3.3 0.89 -11.74% slower
pkpd/sim_one_comp_mm_elim_abs.stan 0.32 0.32 0.98 -1.89% slower
arK/arK.stan 1.74 1.8 0.97 -3.06% slower
arma/arma.stan 0.65 0.67 0.98 -2.32% slower
garch/garch.stan 0.51 0.52 0.99 -1.06% slower
Mean result: 0.979049880375

Jenkins Console Log
Blue Ocean
Commit hash: e6eeaf9


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

@syclik
Copy link
Member

syclik commented Apr 28, 2020

@peterwicksstringfield, this is awesome! I think you brought up a comment about performance. It seems like it's something we need to check before we consider this change, if I understood your comment correctly. Otherwise, this change cleans up a lot of code; thank you!

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.

@peterwicksstringfield I needed something like this for a pull request I was working on (#1962), so I went through and reviewed this and I agree with @syclik that this is good to go.

I can write a couple microbenchmarks on the checks if you think they're necessary.

I have one question about the csr stuff, and the release notes can go in the pull request text instead of into the release notes file itself.

Do you have time to look at this?

@bbbales2
Copy link
Member

bbbales2 commented Jul 4, 2020

Yo @SteveBronder, do you know the answer to the question here: #1798 (comment)? I see you have a pull request open with something about u and z.

@bbbales2
Copy link
Member

bbbales2 commented Jul 9, 2020

@peterwicksstringfield I pulled out the release notes and put them in the pull request and merged develop into your branch.

@syclik can you give my changes a once over? I guess I'm not supposed to merge this now that I've touched it.

Edit: My changes are this and this

@stan-buildbot
Copy link
Contributor


Name Old Result New Result Ratio Performance change( 1 - new / old )
gp_pois_regr/gp_pois_regr.stan 4.0 4.4 0.91 -10.18% slower
low_dim_corr_gauss/low_dim_corr_gauss.stan 0.02 0.02 0.97 -2.81% slower
eight_schools/eight_schools.stan 0.09 0.09 0.99 -1.19% slower
gp_regr/gp_regr.stan 0.19 0.19 0.98 -1.69% slower
irt_2pl/irt_2pl.stan 5.47 5.44 1.01 0.6% faster
performance.compilation 87.37 85.79 1.02 1.81% faster
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan 7.72 8.39 0.92 -8.64% slower
pkpd/one_comp_mm_elim_abs.stan 20.95 20.36 1.03 2.79% faster
sir/sir.stan 94.63 92.6 1.02 2.14% faster
gp_regr/gen_gp_data.stan 0.04 0.04 0.99 -0.93% slower
low_dim_gauss_mix/low_dim_gauss_mix.stan 3.01 3.28 0.92 -9.08% slower
pkpd/sim_one_comp_mm_elim_abs.stan 0.36 0.31 1.16 14.05% faster
arK/arK.stan 1.77 1.81 0.98 -1.79% slower
arma/arma.stan 0.72 0.69 1.06 5.22% faster
garch/garch.stan 0.52 0.6 0.87 -15.27% slower
Mean result: 0.988229972194

Jenkins Console Log
Blue Ocean
Commit hash: 09336d0


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

@serban-nicusor-toptal
Copy link
Contributor

Hey @bbbales2, one of the windows machines was unstable. I've turned it off for the moment and spin up a temporary one to not block the builds.
I've restarted this build, it should complete just fine now, Sorry for the inconvenience!

@stan-buildbot
Copy link
Contributor


Name Old Result New Result Ratio Performance change( 1 - new / old )
gp_pois_regr/gp_pois_regr.stan 4.04 4.17 0.97 -3.08% slower
low_dim_corr_gauss/low_dim_corr_gauss.stan 0.02 0.02 1.01 0.71% faster
eight_schools/eight_schools.stan 0.09 0.1 0.94 -6.88% slower
gp_regr/gp_regr.stan 0.19 0.19 0.99 -0.85% slower
irt_2pl/irt_2pl.stan 5.37 5.42 0.99 -1.02% slower
performance.compilation 86.37 85.82 1.01 0.64% faster
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan 7.7 8.46 0.91 -9.79% slower
pkpd/one_comp_mm_elim_abs.stan 20.8 21.27 0.98 -2.28% slower
sir/sir.stan 92.26 91.3 1.01 1.04% faster
gp_regr/gen_gp_data.stan 0.04 0.04 0.99 -0.98% slower
low_dim_gauss_mix/low_dim_gauss_mix.stan 3.04 3.45 0.88 -13.55% slower
pkpd/sim_one_comp_mm_elim_abs.stan 0.32 0.31 1.02 2.27% faster
arK/arK.stan 1.77 1.81 0.98 -2.29% slower
arma/arma.stan 0.73 0.68 1.07 6.76% faster
garch/garch.stan 0.52 0.61 0.84 -18.54% slower
Mean result: 0.972518033857

Jenkins Console Log
Blue Ocean
Commit hash: 09336d0


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.03 4.12 0.98 -2.23% slower
low_dim_corr_gauss/low_dim_corr_gauss.stan 0.02 0.02 0.99 -0.98% slower
eight_schools/eight_schools.stan 0.09 0.09 1.02 2.05% faster
gp_regr/gp_regr.stan 0.19 0.19 0.98 -1.53% slower
irt_2pl/irt_2pl.stan 5.36 5.45 0.98 -1.77% slower
performance.compilation 87.64 85.74 1.02 2.17% faster
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan 7.77 8.39 0.93 -7.96% slower
pkpd/one_comp_mm_elim_abs.stan 20.57 20.36 1.01 1.02% faster
sir/sir.stan 93.85 91.58 1.02 2.43% faster
gp_regr/gen_gp_data.stan 0.04 0.04 0.99 -0.77% slower
low_dim_gauss_mix/low_dim_gauss_mix.stan 3.05 3.31 0.92 -8.7% slower
pkpd/sim_one_comp_mm_elim_abs.stan 0.32 0.31 1.03 3.29% faster
arK/arK.stan 1.79 1.82 0.98 -1.83% slower
arma/arma.stan 0.72 0.64 1.13 11.19% faster
garch/garch.stan 0.52 0.6 0.86 -16.0% slower
Mean result: 0.99046230634

Jenkins Console Log
Blue Ocean
Commit hash: 09336d0


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

bbbales2 commented Jul 12, 2020

This is good, but someone should check my changes (this and this) before doing the final merge.

This will also conflict with the variadic ODEs. Both make some changes to check_finite. The changes here are better and we should have them (edit: see here).

Copy link
Member

@syclik syclik left a comment

Choose a reason for hiding this comment

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

LGTM! (also! I saw @bbbales2 approved it)

@syclik
Copy link
Member

syclik commented Jul 14, 2020

@bbbales2, I'm assuming the release notes are correct. The changes to the test look fine.

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.

8 participants