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(Vec1&& v1, Vec2&& v2) {
25 check_matching_sizes("dot_product", "v1", v1, "v2", v2);
26 return make_holder(
27 [](auto&& v1_, auto&& v2_) {
28 return std::forward<decltype(v1_)>(v1_).dot(
29 std::forward<decltype(v2_)>(v2_));
30 },
31 std::forward<Vec1>(v1), std::forward<Vec2>(v2));
32}
33
41template <typename Scalar1, typename Scalar2,
44inline auto dot_product(const Scalar1* v1, const Scalar2* v2, size_t length) {
46 for (size_t i = 0; i < length; i++) {
47 result += v1[i] * v2[i];
48 }
49 return result;
50}
51
59template <typename Scalar1, typename Scalar2, typename Alloc1, typename Alloc2,
62 const std::vector<Scalar1, Alloc1>& v1,
63 const std::vector<Scalar2, Alloc2>& v2) {
64 check_matching_sizes("dot_product", "v1", v1, "v2", v2);
65
66 if (v1.size() == 0) {
67 return 0.0;
68 }
69
72}
73
74} // namespace math
75} // namespace stan
76
77#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:109
auto make_holder(F &&func, Args &&... args)
Calls given function with given arguments.
Definition holder.hpp:481
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 ...