Automatic Differentiation
 
Loading...
Searching...
No Matches
dot_product.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_DOT_PRODUCT_HPP
2#define STAN_MATH_PRIM_FUN_DOT_PRODUCT_HPP
3
7#include <vector>
8
9namespace stan {
10namespace math {
11
21template <typename Vec1, typename Vec2,
22 require_all_eigen_vector_t<Vec1, Vec2> * = nullptr,
23 require_not_var_t<return_type_t<Vec1, Vec2>> * = nullptr>
24inline auto dot_product(const Vec1 &v1, const Vec2 &v2) {
25 check_matching_sizes("dot_product", "v1", v1, "v2", v2);
26 return v1.dot(v2);
27}
28
36template <typename Scalar1, typename Scalar2,
39inline auto dot_product(const Scalar1 *v1, const Scalar2 *v2, size_t length) {
41 for (size_t i = 0; i < length; i++) {
42 result += v1[i] * v2[i];
43 }
44 return result;
45}
46
54template <typename Scalar1, typename Scalar2, typename Alloc1, typename Alloc2,
57 const std::vector<Scalar1, Alloc1> &v1,
58 const std::vector<Scalar2, Alloc2> &v2) {
59 check_matching_sizes("dot_product", "v1", v1, "v2", v2);
60
61 if (v1.size() == 0) {
62 return 0.0;
63 }
64
67}
68
69} // namespace math
70} // namespace stan
71
72#endif
auto as_column_vector_or_scalar(T &&a)
as_column_vector_or_scalar of a kernel generator expression.
require_all_t< is_stan_scalar< std::decay_t< Types > >... > require_all_stan_scalar_t
Require all of the types satisfy is_stan_scalar.
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
require_all_not_t< is_var< std::decay_t< Types > >... > require_all_not_var_t
Require none of the types satisfy is_var.
Definition is_var.hpp:44
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.
auto dot_product(const T_a &a, const T_b &b)
Returns the dot product of the specified vectors.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...