Skip to content

Commit 4fdc43b

Browse files
authored
Merge pull request #2884 from stan-dev/fix/2883-eigenvalues-sym-returntype
Fix eigenvalues_sym return type
2 parents f6cb7da + 100182e commit 4fdc43b

3 files changed

Lines changed: 4 additions & 7 deletions

File tree

stan/math/prim/fun/eigenvalues_sym.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ namespace math {
2121
*/
2222
template <typename EigMat, require_eigen_matrix_dynamic_t<EigMat>* = nullptr,
2323
require_not_st_var<EigMat>* = nullptr>
24-
Eigen::Matrix<value_type_t<EigMat>, Eigen::Dynamic, 1> eigenvalues_sym(
25-
const EigMat& m) {
24+
Eigen::Vector<value_type_t<EigMat>, -1> eigenvalues_sym(const EigMat& m) {
2625
using PlainMat = plain_type_t<EigMat>;
2726
const PlainMat& m_eval = m;
2827
check_nonzero_size("eigenvalues_sym", "m", m_eval);

stan/math/rev/fun/eigenvalues_sym.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ namespace math {
2323
*/
2424
template <typename T, require_rev_matrix_t<T>* = nullptr>
2525
inline auto eigenvalues_sym(const T& m) {
26-
using return_t = return_var_matrix_t<T>;
27-
if (unlikely(m.size() == 0)) {
28-
return return_t(m);
29-
}
26+
using return_t = return_var_matrix_t<Eigen::VectorXd, T>;
27+
check_nonzero_size("eigenvalues_sym", "m", m);
3028
check_symmetric("eigenvalues_sym", "m", m);
3129

3230
auto arena_m = to_arena(m);

test/unit/math/rev/fun/eigenvalues_sym_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ TEST(AgradRev, eigenvaluesSymLogDet) {
1717
stan::math::matrix_d a_inv = stan::math::inverse(a);
1818

1919
stan::math::matrix_v a_v(a);
20-
auto w = eigenvalues_sym(a_v);
20+
stan::math::matrix_v w = eigenvalues_sym(a_v);
2121
auto logdet = stan::math::sum(stan::math::log(w));
2222

2323
stan::math::set_zero_all_adjoints();

0 commit comments

Comments
 (0)