Skip to content

Commit

Permalink
Replace ad-hoc DiagonalWrapper with built-in Eigen approach
Browse files Browse the repository at this point in the history
As far as I can tell, this is mathematically and operationally
equivalent, but using Eigen's built-in functionality for producing a
diagonal matrix expression from a 1-d array solves issue
#419.
  • Loading branch information
peddie committed May 18, 2023
1 parent 1e1f466 commit 8faa450
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions include/albatross/src/core/transformed_distribution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,12 @@ namespace albatross {

namespace details {

template <typename X> inline auto diagonal_wrapper(X &x) {
return Eigen::DiagonalWrapper<X>(x);
}

template <typename MatrixType, typename DiagType>
inline Eigen::MatrixXd
product_sqrt(const Eigen::MatrixBase<MatrixType> &matrix,
const Eigen::DiagonalBase<DiagType> &diag_matrix) {

return matrix.derived() *
diagonal_wrapper(diag_matrix.diagonal().array().sqrt().eval());
diag_matrix.diagonal().array().sqrt().matrix().asDiagonal();
}

template <typename Lhs, typename Rhs>
Expand All @@ -61,7 +56,7 @@ inline Eigen::MatrixXd
product_sqrt(const Eigen::SparseMatrixBase<MatrixType> &matrix,
const Eigen::DiagonalBase<DiagType> &diag_matrix) {
return matrix.derived() *
diagonal_wrapper(diag_matrix.diagonal().array().sqrt().eval());
diag_matrix.diagonal().array().sqrt().matrix().asDiagonal();
}

template <typename SparseType, typename MatrixType>
Expand Down

0 comments on commit 8faa450

Please sign in to comment.