Skip to content

Commit 4430597

Browse files
committed
Allow size-0 matrices
1 parent e436e8f commit 4430597

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

stan/math/prim/fun/complex_schur_decompose.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ namespace math {
2727
template <typename M, require_eigen_dense_dynamic_t<M>* = nullptr>
2828
inline Eigen::Matrix<complex_return_t<scalar_type_t<M>>, -1, -1>
2929
complex_schur_decompose_u(const M& m) {
30-
check_nonzero_size("complex_schur_decompose_u", "m", m);
30+
if (m.size() == 0)
31+
return m;
3132
check_square("complex_schur_decompose_u", "m", m);
3233
using MatType = Eigen::Matrix<scalar_type_t<M>, -1, -1>;
3334
// copy because ComplexSchur requires Eigen::Matrix type
@@ -50,7 +51,8 @@ complex_schur_decompose_u(const M& m) {
5051
template <typename M, require_eigen_dense_dynamic_t<M>* = nullptr>
5152
inline Eigen::Matrix<complex_return_t<scalar_type_t<M>>, -1, -1>
5253
complex_schur_decompose_t(const M& m) {
53-
check_nonzero_size("complex_schur_decompose_t", "m", m);
54+
if (m.size() == 0)
55+
return m;
5456
check_square("complex_schur_decompose_t", "m", m);
5557
using MatType = Eigen::Matrix<scalar_type_t<M>, -1, -1>;
5658
// copy because ComplexSchur requires Eigen::Matrix type

test/unit/math/mix/fun/complex_schur_decompose_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ TEST(mathMixFun, complexSchurDecompose) {
6666
using ffd_t = stan::math::fvar<fd_t>;
6767
using fv_t = stan::math::fvar<v_t>;
6868
using ffv_t = stan::math::fvar<fv_t>;
69-
for (const auto& x : stan::test::square_test_matrices(1, 3)) {
69+
for (const auto& x : stan::test::square_test_matrices(0, 3)) {
7070
test_complex_schur_decompose<d_t>(x);
7171
test_complex_schur_decompose<v_t>(x);
7272
test_complex_schur_decompose<fd_t>(x);
7373
test_complex_schur_decompose<ffd_t>(x);
7474
test_complex_schur_decompose<fv_t>(x);
7575
test_complex_schur_decompose<ffv_t>(x);
7676
}
77-
for (const auto& x : stan::test::square_test_matrices(1, 3)) {
77+
for (const auto& x : stan::test::square_test_matrices(0, 3)) {
7878
test_complex_schur_decompose_complex<d_t>(x);
7979
test_complex_schur_decompose_complex<v_t>(x);
8080
test_complex_schur_decompose_complex<fd_t>(x);

0 commit comments

Comments
 (0)