Skip to content

Commit

Permalink
Change return style for empty matrices
Browse files Browse the repository at this point in the history
  • Loading branch information
mcol committed Feb 12, 2020
1 parent 2f875bd commit 310f2e1
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion stan/math/fwd/fun/crossprod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ template <typename T, int R, int C>
inline Eigen::Matrix<fvar<T>, C, C> crossprod(
const Eigen::Matrix<fvar<T>, R, C>& m) {
if (m.rows() == 0) {
return Eigen::Matrix<fvar<T>, C, C>(0, 0);
return {};
}
return multiply(transpose(m), m);
}
Expand Down
2 changes: 1 addition & 1 deletion stan/math/fwd/fun/multiply_lower_tri_self_transpose.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ template <typename T, int R, int C>
inline Eigen::Matrix<fvar<T>, R, R> multiply_lower_tri_self_transpose(
const Eigen::Matrix<fvar<T>, R, C>& m) {
if (m.rows() == 0) {
return Eigen::Matrix<fvar<T>, R, R>(0, 0);
return {};
}
Eigen::Matrix<fvar<T>, R, C> L(m.rows(), m.cols());
L.setZero();
Expand Down
2 changes: 1 addition & 1 deletion stan/math/fwd/fun/tcrossprod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ template <typename T, int R, int C>
inline Eigen::Matrix<fvar<T>, R, R> tcrossprod(
const Eigen::Matrix<fvar<T>, R, C>& m) {
if (m.rows() == 0) {
return Eigen::Matrix<fvar<T>, R, R>(0, 0);
return {};
}
return multiply(m, transpose(m));
}
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/tcrossprod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace math {
template <int R, int C>
inline Eigen::MatrixXd tcrossprod(const Eigen::Matrix<double, R, C>& M) {
if (M.rows() == 0) {
return matrix_d(0, 0);
return {};
}
if (M.rows() == 1) {
return M * M.transpose();
Expand Down
5 changes: 2 additions & 3 deletions stan/math/prim/fun/to_matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ inline Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> to_matrix(
const std::vector<Eigen::Matrix<T, 1, Eigen::Dynamic> >& x) {
int rows = x.size();
if (rows == 0) {
return Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>(0, 0);
return {};
}
int cols = x[0].size();
Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> result(rows, cols);
Expand All @@ -65,8 +65,7 @@ inline Eigen::Matrix<return_type_t<T, double>, Eigen::Dynamic, Eigen::Dynamic>
to_matrix(const std::vector<std::vector<T> >& x) {
size_t rows = x.size();
if (rows == 0) {
return Eigen::Matrix<return_type_t<T, double>, Eigen::Dynamic,
Eigen::Dynamic>(0, 0);
return {};
}
size_t cols = x[0].size();
Eigen::Matrix<return_type_t<T, double>, Eigen::Dynamic, Eigen::Dynamic>
Expand Down
2 changes: 1 addition & 1 deletion stan/math/rev/fun/inverse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class inverse_vari : public vari {
inline matrix_v inverse(const matrix_v &m) {
check_square("inverse", "m", m);
if (m.size() == 0) {
return matrix_v(0, 0);
return {};
}

matrix_v res(m.rows(), m.cols());
Expand Down
2 changes: 1 addition & 1 deletion stan/math/rev/fun/tcrossprod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ template <int R, int C>
inline Eigen::Matrix<var, -1, -1> tcrossprod(
const Eigen::Matrix<var, R, C>& M) {
if (M.rows() == 0) {
return matrix_v(0, 0);
return {};
}
// if (M.rows() == 1)
// return M * M.transpose();
Expand Down

0 comments on commit 310f2e1

Please sign in to comment.