Stan Math Library  2.20.0
reverse mode automatic differentiation
distance.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_DISTANCE_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_DISTANCE_HPP
3 
8 #include <boost/math/tools/promotion.hpp>
9 
10 namespace stan {
11 namespace math {
12 
22 template <typename T1, int R1, int C1, typename T2, int R2, int C2>
23 inline typename boost::math::tools::promote_args<T1, T2>::type distance(
24  const Eigen::Matrix<T1, R1, C1>& v1, const Eigen::Matrix<T2, R2, C2>& v2) {
25  using std::sqrt;
26  check_vector("distance", "v1", v1);
27  check_vector("distance", "v2", v2);
28  check_matching_sizes("distance", "v1", v1, "v2", v2);
29  return sqrt(squared_distance(v1, v2));
30 }
31 
32 } // namespace math
33 } // namespace stan
34 #endif
fvar< T > sqrt(const fvar< T > &x)
Definition: sqrt.hpp:13
void check_vector(const char *function, const char *name, const Eigen::Matrix< T, R, C > &x)
Check if the matrix is either a row vector or column vector.
fvar< T > squared_distance(const Eigen::Matrix< fvar< T >, R, C > &v1, const Eigen::Matrix< double, R, C > &v2)
Returns the squared distance between the specified vectors of the same dimensions.
void check_matching_sizes(const char *function, const char *name1, const T_y1 &y1, const char *name2, const T_y2 &y2)
Check if two structures at the same size.
boost::math::tools::promote_args< T1, T2 >::type distance(const Eigen::Matrix< T1, R1, C1 > &v1, const Eigen::Matrix< T2, R2, C2 > &v2)
Returns the distance between the specified vectors.
Definition: distance.hpp:23

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