determinant.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_FWD_MAT_FUN_DETERMINANT_HPP
#define STAN_MATH_FWD_MAT_FUN_DETERMINANT_HPP
#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/mat/fun/typedefs.hpp>
#include <stan/math/prim/mat/fun/multiply.hpp>
#include <stan/math/fwd/mat/fun/multiply.hpp>
#include <stan/math/prim/mat/fun/inverse.hpp>
#include <stan/math/fwd/mat/fun/inverse.hpp>
#include <stan/math/prim/mat/err/check_square.hpp>
#include <boost/math/tools/promotion.hpp>
#include <vector>
namespace stan {
namespace math {
template<typename T, int R, int C>
inline
fvar<T>
determinant(const Eigen::Matrix<fvar<T>, R, C>& m) {
check_square("determinant", "m", m);
Eigen::Matrix<T, R, C> m_deriv(m.rows(), m.cols());
Eigen::Matrix<T, R, C> m_val(m.rows(), m.cols());
for (size_type i = 0; i < m.rows(); i++) {
for (size_type j = 0; j < m.cols(); j++) {
m_deriv(i, j) = m(i, j).d_;
m_val(i, j) = m(i, j).val_;
}
}
Eigen::Matrix<T, R, C> m_inv = inverse(m_val);
m_deriv = multiply(m_inv, m_deriv);
fvar<T> result;
result.val_ = m_val.determinant();
result.d_ = result.val_ * m_deriv.trace();
// FIXME: I think this will overcopy compared to retur fvar<T>(...);
return result;
}
}
}
#endif
typedefs.hpp
multiply.hpp
core.hpp
stan::math::fvar::d_
T d_
Definition: fvar.hpp:16
stan
Definition: log_sum_exp.hpp:8
stan::math::multiply
Eigen::Matrix< fvar< T >, R1, C1 > multiply(const Eigen::Matrix< fvar< T >, R1, C1 > &m, const fvar< T > &c)
Definition: multiply.hpp:20
multiply.hpp
stan::math::size_type
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic >::Index size_type
Type for sizes and indexes in an Eigen matrix with double e.
Definition: typedefs.hpp:13
stan::math::inverse
Eigen::Matrix< fvar< T >, R, C > inverse(const Eigen::Matrix< fvar< T >, R, C > &m)
Definition: inverse.hpp:20
stan::math::fvar::val_
T val_
Definition: fvar.hpp:15
stan::math::determinant
fvar< T > determinant(const Eigen::Matrix< fvar< T >, R, C > &m)
Definition: determinant.hpp:21
inverse.hpp
inverse.hpp
Eigen.hpp
stan::math::check_square
void check_square(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
Check if the specified matrix is square.
Definition: check_square.hpp:27
stan::math::fvar
Definition: fvar.hpp:14
check_square.hpp

[ Stan Home Page ] © 2011–2016, Stan Development Team.