-
-
Notifications
You must be signed in to change notification settings - Fork 187
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
better handling of size 0 inputs #1517
Conversation
The following don't fail, but provide more coverage for corner cases: test/unit/math/mix/mat/fun/matrix_exp_multiply_test.cpp test/unit/math/mix/mat/fun/matrix_exp_pade_test.cpp test/unit/math/mix/mat/fun/trace_inv_quad_form_ldlt_test.cpp
(stat_comp_benchmarks/benchmarks/gp_pois_regr/gp_pois_regr.stan, 0.99) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for cleaning these up! Two minor return cleanups then its good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Thanks for the quick fixes.
…stable/2017-11-14)
(stat_comp_benchmarks/benchmarks/gp_pois_regr/gp_pois_regr.stan, 0.99) |
Summary
The following is done:
matrix_exp_multiply
,scale_matrix_exp_multiply
andmatrix_exp_pade
: movecheck_square
at the beginning, so that it throws ifA
is not square (currently it returns an empty matrix if any dimension is 0)scale_matrix_exp_multiply
: it returns a rectangular matrix with 0 rows ifA
is empty andB
has zero rows (currently it returns a square empty matrix)mdivide_left_ldlt
: it returns a rectangular matrix with 0 rows ifA
is empty andb
has zero rows (currently it returns a square empty matrix)mdivide_right_ldlt
: it returns a rectangular matrix with 0 columns ifA
is empty andb
has zero columns (currently it returns a square empty matrix)trace_inv_quad_form_ldlt
: useB.rows()
instead ofB.size()
, so we ensure that matrices are multipliable before returning 0This also:
check_symmetric
by checking if the size of the square matrix is 0check_corr_matrix
, so that for size 0 matrix it returns instead of throwingFixes #1515.
Tests
I've added a bunch of tests that check for all of the above. It's still worth checking for more cases that I might have missed. I'm also not entirely convinced that my mental mapping of prim/rev/mix is complete or correct, so it's possible I've missed something.
Side Effects
None.
Checklist
Math issue Improve handling of size 0 inputs #1515
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
./runTests.py test/unit
)make test-headers
)make doxygen
)make cpplint
)the code is written in idiomatic C++ and changes are documented in the doxygen
the new changes are tested