1 #ifndef STAN_MATH_REV_MAT_META_OPERANDS_AND_PARTIALS_HPP 2 #define STAN_MATH_REV_MAT_META_OPERANDS_AND_PARTIALS_HPP 18 typedef std::vector<var>
Op;
23 : partials_(partials_t::Zero(op.size())),
24 partials_vec_(partials_),
28 template <
typename,
typename,
typename,
typename,
typename,
typename>
32 void dump_partials(
double* partials) {
33 for (
int i = 0; i < this->partials_.size(); ++i) {
34 partials[i] = this->partials_[i];
37 void dump_operands(
vari** varis) {
38 for (
size_t i = 0; i < this->operands_.size(); ++i) {
39 varis[i] = this->operands_[i].vi_;
42 int size() {
return this->operands_.size(); }
45 template <
int R,
int C>
48 typedef Eigen::Matrix<var, R, C>
Op;
53 : partials_(partials_t::Zero(ops.
rows(), ops.
cols())),
54 partials_vec_(partials_),
58 template <
typename,
typename,
typename,
typename,
typename,
typename>
62 void dump_operands(
vari** varis) {
63 for (
int i = 0; i < this->operands_.size(); ++i) {
64 varis[i] = this->operands_(i).vi_;
67 void dump_partials(
double* partials) {
68 for (
int i = 0; i < this->partials_.size(); ++i) {
72 int size() {
return this->operands_.size(); }
77 template <
int R,
int C>
80 typedef std::vector<Eigen::Matrix<var, R, C> >
Op;
84 : partials_vec_(ops.
size()), operands_(ops) {
85 for (
size_t i = 0; i < ops.size(); ++i) {
86 partials_vec_[i] = partial_t::Zero(ops[i].
rows(), ops[i].
cols());
91 template <
typename,
typename,
typename,
typename,
typename,
typename>
95 void dump_partials(
double* partials) {
97 for (
size_t i = 0; i < this->partials_vec_.size(); ++i) {
98 for (
int j = 0; j < this->partials_vec_[i].size(); ++j, ++p_i) {
99 partials[p_i] = this->partials_vec_[i](j);
103 void dump_operands(
vari** varis) {
105 for (
size_t i = 0; i < this->operands_.size(); ++i) {
106 for (
int j = 0; j < this->operands_[i].size(); ++j, ++p_i) {
107 varis[p_i] = this->operands_[i](j).vi_;
112 if (
unlikely(this->operands_.size() == 0))
114 return this->operands_.size() * this->operands_[0].size();
121 typedef std::vector<std::vector<var> >
Op;
125 : partials_vec_(
length(ops)), operands_(ops) {
126 for (
size_t i = 0; i <
length(ops); ++i) {
127 partials_vec_[i] = partial_t(
length(ops[i]), 0.0);
132 template <
typename,
typename,
typename,
typename,
typename,
typename>
136 void dump_partials(
double* partials) {
138 for (
size_t i = 0; i < this->partials_vec_.size(); ++i) {
139 for (
size_t j = 0; j < this->partials_vec_[i].size(); ++j, ++p_i) {
140 partials[p_i] = this->partials_vec_[i][j];
144 void dump_operands(
vari** varis) {
146 for (
size_t i = 0; i < this->operands_.size(); ++i) {
147 for (
size_t j = 0; j < this->operands_[i].size(); ++j, ++p_i) {
148 varis[p_i] = this->operands_[i][j].vi_;
153 if (
unlikely(this->operands_.size() == 0))
155 return this->operands_.size() * this->operands_[0].size();
int rows(const Eigen::Matrix< T, R, C > &m)
Return the number of rows in the specified matrix, vector, or row vector.
An edge holds both the operands and its associated partial derivatives.
std::vector< Eigen::Matrix< var, R, C > > Op
This template builds partial derivatives with respect to a set of operands.
The variable implementation base class.
size_t length(const std::vector< T > &x)
Returns the length of the provided std::vector.
Eigen::Matrix< var, R, C > Op
std::vector< partial_t > partials_vec_
(Expert) Numerical traits for algorithmic differentiation variables.
std::vector< std::vector< var > > Op
broadcast_array< partials_t > partials_vec_
ops_partials_edge(const Op &ops)
std::vector< double > partial_t
broadcast_array< partials_t > partials_vec_
ops_partials_edge(const Op &ops)
empty_broadcast_array< ViewElt, Op > partials_
int cols(const Eigen::Matrix< T, R, C > &m)
Return the number of columns in the specified matrix, vector, or row vector.
int size(const std::vector< T > &x)
Return the size of the specified standard vector.
ops_partials_edge(const Op &op)
std::vector< partial_t > partials_vec_
Eigen::VectorXd partials_t
Eigen::Matrix< double, -1, -1 > partial_t
ops_partials_edge(const Op &ops)
Eigen::Matrix< double, R, C > partials_t