All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
sum.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_REV_MAT_FUN_SUM_HPP
#define STAN_MATH_REV_MAT_FUN_SUM_HPP
#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <stan/math/prim/mat/fun/typedefs.hpp>
#include <stan/math/rev/core.hpp>
#include <stan/math/rev/arr/fun/sum.hpp>
namespace stan {
namespace math {
class sum_eigen_v_vari : public sum_v_vari {
protected:
template <typename Derived>
inline static double sum_of_val(const Eigen::DenseBase<Derived>& v) {
double result = 0;
for (int i = 0; i < v.size(); i++)
result += v(i).vi_->val_;
return result;
}
public:
template <int R1, int C1>
explicit sum_eigen_v_vari(const Eigen::Matrix<var, R1, C1> &v1)
: sum_v_vari(sum_of_val(v1),
reinterpret_cast<vari**>(ChainableStack::memalloc_
.alloc(v1.size()
* sizeof(vari*))),
v1.size()) {
for (size_t i = 0; i < length_; i++)
v_[i] = v1(i).vi_;
}
};
template <int R, int C>
inline var sum(const Eigen::Matrix<var, R, C>& m) {
if (m.size() == 0)
return 0.0;
return var(new sum_eigen_v_vari(m));
}
}
}
#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)
Return the size of the specified standard vector.
Definition: size.hpp:17
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.