| Stan Math Library 2.6.3 probability, sampling & optimization

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
sum.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_REV_MAT_FUN_SUM_HPP
2 #define STAN_MATH_REV_MAT_FUN_SUM_HPP
3
4 #include <stan/math/prim/mat/fun/Eigen.hpp>
5 #include <stan/math/prim/mat/fun/typedefs.hpp>
6 #include <stan/math/rev/core.hpp>
7 #include <stan/math/rev/arr/fun/sum.hpp>
8
9 namespace stan {
10 namespace math {
11
17 class sum_eigen_v_vari : public sum_v_vari {
18 protected:
19 template <typename Derived>
20 inline static double sum_of_val(const Eigen::DenseBase<Derived>& v) {
21 double result = 0;
22 for (int i = 0; i < v.size(); i++)
23 result += v(i).vi_->val_;
24 return result;
25 }
26
27 public:
28 template <int R1, int C1>
29 explicit sum_eigen_v_vari(const Eigen::Matrix<var, R1, C1> &v1)
30 : sum_v_vari(sum_of_val(v1),
31 reinterpret_cast<vari**>(ChainableStack::memalloc_
32 .alloc(v1.size()
33 * sizeof(vari*))),
34 v1.size()) {
35 for (size_t i = 0; i < length_; i++)
36 v_[i] = v1(i).vi_;
37 }
38 };
39
49 template <int R, int C>
50 inline var sum(const Eigen::Matrix<var, R, C>& m) {
51 if (m.size() == 0)
52 return 0.0;
53 return var(new sum_eigen_v_vari(m));
54 }
55
56 }
57 }
58 #endif
stan::math::sum
fvar< T > sum(const std::vector< fvar< T > > &m)
Return the sum of the entries of the specified standard vector.
Definition: sum.hpp:20
stan::math::sum_v_vari::v_
vari ** v_
Definition: sum.hpp:16
core.hpp
stan::math::sum_eigen_v_vari::sum_eigen_v_vari
sum_eigen_v_vari(const Eigen::Matrix< var, R1, C1 > &v1)
Definition: sum.hpp:29
stan::math::sum_eigen_v_vari::sum_of_val
static double sum_of_val(const Eigen::DenseBase< Derived > &v)
Definition: sum.hpp:20
stan::math::vari
The variable implementation base class.
Definition: vari.hpp:28
stan::math::var
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:32
stan::math::sum_v_vari::length_
size_t length_
Definition: sum.hpp:17
sum.hpp
Eigen.hpp
stan::math::sum_eigen_v_vari
Class for representing sums with constructors for Eigen.
Definition: sum.hpp:17
stan::math::size
int size(const std::vector< T > &x)
Definition: size.hpp:11
stan::math::AutodiffStackStorage
Definition: autodiffstackstorage.hpp:12
stan::math::sum_v_vari
Class for sums of variables constructed with standard vectors.
Definition: sum.hpp:14
typedefs.hpp

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