| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

squared_distance.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_SQUARED_DISTANCE_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_SQUARED_DISTANCE_HPP
3
4 #include <stan/math/prim/mat/fun/Eigen.hpp>
5 #include <stan/math/prim/mat/err/check_vector.hpp>
6 #include <stan/math/prim/arr/err/check_matching_sizes.hpp>
7 #include <stan/math/prim/scal/fun/squared_distance.hpp>
8
9 namespace stan {
10 namespace math {
11
24 template<int R, int C>
25 inline double
26 squared_distance(const Eigen::Matrix<double, R, C>& v1,
27 const Eigen::Matrix<double, R, C>& v2) {
28 check_vector("squared_distance", "v1", v1);
29 check_vector("squared_distance", "v2", v2);
30 check_matching_sizes("squared_distance", "v1", v1, "v2", v2);
31 return (v1-v2).squaredNorm();
32 }
33
48 template<int R1, int C1, int R2, int C2>
49 inline double
50 squared_distance(const Eigen::Matrix<double, R1, C1>& v1,
51 const Eigen::Matrix<double, R2, C2>& v2) {
52 check_vector("squared_distance", "v1", v1);
53 check_vector("squared_distance", "v2", v2);
54 check_matching_sizes("squared_distance", "v1", v1, "v2", v2);
55 return (v1.transpose()-v2).squaredNorm();
56 }
57
58 }
59 }
60 #endif
stan::math::check_vector
bool check_vector(const char *function, const char *name, const Eigen::Matrix< T, R, C > &x)
Return true if the matrix is either a row vector or column vector.
Definition: check_vector.hpp:34
stan
Definition: log_sum_exp.hpp:8
check_matching_sizes.hpp
stan::math::squared_distance
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.
Definition: squared_distance.hpp:30
squared_distance.hpp
stan::math::check_matching_sizes
bool check_matching_sizes(const char *function, const char *name1, const T_y1 &y1, const char *name2, const T_y2 &y2)
Return true if two structures at the same size.
Definition: check_matching_sizes.hpp:29
Eigen.hpp
check_vector.hpp

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