1 #ifndef STAN_MATH_REV_MAT_FUN_SQUARED_DISTANCE_HPP 2 #define STAN_MATH_REV_MAT_FUN_SQUARED_DISTANCE_HPP 22 template <
int R1,
int C1,
int R2,
int C2>
24 const Eigen::Matrix<var, R1, C1>& v1,
25 const Eigen::Matrix<var, R2, C2>& v2) {
29 for (idx_t i = 0; i < v1.size(); i++) {
30 double diff = v1(i).vi_->val_ - v2(i).vi_->val_;
31 result += diff * diff;
37 template <
int R1,
int C1,
int R2,
int C2>
39 const Eigen::Matrix<var, R2, C2>& v2)
41 v1_ =
reinterpret_cast<vari**
>(
43 for (
size_t i = 0; i <
length_; i++)
46 v2_ =
reinterpret_cast<vari**
>(
48 for (
size_t i = 0; i <
length_; i++)
52 for (
size_t i = 0; i <
length_; i++) {
65 template <
int R1,
int C1,
int R2,
int C2>
67 const Eigen::Matrix<var, R1, C1>& v1,
68 const Eigen::Matrix<double, R2, C2>& v2) {
73 for (idx_t i = 0; i < v1.size(); i++) {
74 double diff = v1(i).vi_->val_ - v2(i);
75 result += diff * diff;
81 template <
int R1,
int C1,
int R2,
int C2>
83 const Eigen::Matrix<double, R2, C2>& v2)
85 v1_ =
reinterpret_cast<vari**
>(
87 for (
size_t i = 0; i <
length_; i++)
90 v2_ =
reinterpret_cast<double*
>(
92 for (
size_t i = 0; i <
length_; i++)
96 for (
size_t i = 0; i <
length_; i++) {
103 template <
int R1,
int C1,
int R2,
int C2>
105 const Eigen::Matrix<var, R2, C2>& v2) {
111 template <
int R1,
int C1,
int R2,
int C2>
113 const Eigen::Matrix<double, R2, C2>& v2) {
119 template <
int R1,
int C1,
int R2,
int C2>
121 const Eigen::Matrix<var, R2, C2>& v2) {
static double var_squared_distance(const Eigen::Matrix< var, R1, C1 > &v1, const Eigen::Matrix< var, R2, C2 > &v2)
The variable implementation base class.
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.
static STAN_THREADS_DEF AutodiffStackStorage * instance_
Independent (input) and dependent (output) variables for gradients.
const double val_
The value of this variable.
virtual void chain()
Apply the chain rule to this variable based on the variables on which it depends. ...
Primary template class for the metaprogram to compute the index type of a container.
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.
squared_distance_vv_vari(const Eigen::Matrix< var, R1, C1 > &v1, const Eigen::Matrix< var, R2, C2 > &v2)
squared_distance_vd_vari(const Eigen::Matrix< var, R1, C1 > &v1, const Eigen::Matrix< double, R2, C2 > &v2)
virtual void chain()
Apply the chain rule to this variable based on the variables on which it depends. ...
int size(const std::vector< T > &x)
Return the size of the specified standard vector.
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.
double adj_
The adjoint of this variable, which is the partial derivative of this variable with respect to the ro...
static double var_squared_distance(const Eigen::Matrix< var, R1, C1 > &v1, const Eigen::Matrix< double, R2, C2 > &v2)
void * alloc(size_t len)
Return a newly allocated block of memory of the appropriate size managed by the stack allocator...