Automatic Differentiation
 
Loading...
Searching...
No Matches
scale_matrix_exp_multiply.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_SCALE_MATRIX_EXP_MULTIPLY_HPP
2#define STAN_MATH_PRIM_FUN_SCALE_MATRIX_EXP_MULTIPLY_HPP
3
9
10namespace stan {
11namespace math {
12
27template <typename EigMat1, typename EigMat2,
28 require_all_eigen_vt<std::is_arithmetic, EigMat1, EigMat2>* = nullptr>
29inline Eigen::Matrix<double, Eigen::Dynamic,
30 std::decay_t<EigMat2>::ColsAtCompileTime>
31scale_matrix_exp_multiply(const double t, EigMat1&& A, EigMat2&& B) {
32 check_square("scale_matrix_exp_multiply", "input matrix", A);
33 check_multiplicable("scale_matrix_exp_multiply", "A", A, "B", B);
34 if (A.size() == 0) {
35 return {0, B.cols()};
36 }
38 to_ref(std::forward<EigMat1>(A)), to_ref(std::forward<EigMat2>(B)), t);
39}
40
55template <typename Tt, typename EigMat1, typename EigMat2,
58 value_type_t<EigMat2>>* = nullptr>
59inline Eigen::Matrix<return_type_t<Tt, EigMat1, EigMat2>, Eigen::Dynamic,
60 std::decay_t<EigMat2>::ColsAtCompileTime>
61scale_matrix_exp_multiply(const Tt t, EigMat1&& A, EigMat2&& B) {
62 check_square("scale_matrix_exp_multiply", "input matrix", A);
63 check_multiplicable("scale_matrix_exp_multiply", "A", A, "B", B);
64 if (A.size() == 0) {
65 return {0, B.cols()};
66 }
67 return multiply(matrix_exp(multiply(to_ref(std::forward<EigMat1>(A)), t)),
68 to_ref(std::forward<EigMat2>(B)));
69}
70
71} // namespace math
72} // namespace stan
73#endif
Eigen::MatrixXd action(EigMat1 &&mat, EigMat2 &&b, const double t=1.0)
Perform the matrix exponential action exp(A*t)*B.
The implementation of the work by Awad H.
require_any_t< is_autodiff_scalar< std::decay_t< Types > >... > require_any_autodiff_scalar_t
Require any of the types satisfy is_autodiff_scalar.
require_all_t< is_eigen< std::decay_t< Types > >... > require_all_eigen_t
Require all of the types satisfy is_eigen.
Definition is_eigen.hpp:123
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
Eigen::Matrix< double, Eigen::Dynamic, std::decay_t< EigMat2 >::ColsAtCompileTime > scale_matrix_exp_multiply(const double t, EigMat1 &&A, EigMat2 &&B)
Return product of exp(At) and B, where A is a NxN double matrix, B is a NxCb double matrix,...
void check_square(const char *function, const char *name, const T_y &y)
Check if the specified matrix is square.
auto multiply(Mat1 &&m1, Mat2 &&m2)
Return the product of the specified matrices.
Definition multiply.hpp:20
void check_multiplicable(const char *function, const char *name1, const T1 &y1, const char *name2, const T2 &y2)
Check if the matrices can be multiplied.
plain_type_t< EigenMat > matrix_exp(EigenMat &&A_in)
Return the matrix exponential of the input matrix.
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
Definition to_ref.hpp:18
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...