Automatic Differentiation
 
Loading...
Searching...
No Matches
vari.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_CORE_VARI_HPP
2#define STAN_MATH_REV_CORE_VARI_HPP
3
9#include <ostream>
10#include <type_traits>
11
12namespace stan {
13namespace math {
14
15// forward declaration of vari_value
16template <typename T, typename = void>
18
28class vari_base {
29 public:
34 virtual void chain() = 0;
35 virtual void set_zero_adjoint() = 0;
36
47 static inline void* operator new(size_t nbytes) noexcept {
49 }
50
62 static inline void operator delete(
63 void* /* ignore arg */) noexcept { /* no op */
64 }
65};
66
78template <typename T>
79class vari_value<T, require_t<std::is_floating_point<T>>> : public vari_base {
80 public:
81 using value_type = std::decay_t<T>;
90 value_type adj_{0.0};
91
105 template <typename S, require_convertible_t<S&, T>* = nullptr>
106 vari_value(S x) noexcept : val_(x) { // NOLINT
107 ChainableStack::instance_->var_stack_.push_back(this);
108 }
109
125 template <typename S, require_convertible_t<S&, T>* = nullptr>
126 vari_value(S x, bool stacked) noexcept : val_(x) {
127 if (stacked) {
128 ChainableStack::instance_->var_stack_.push_back(this);
129 } else {
131 }
132 }
133
139 inline const auto& val() const { return val_; }
140
149 inline auto& adj() const { return adj_; }
150
159 inline auto& adj() { return adj_; }
160
161 inline void chain() {}
162
169 inline void init_dependent() noexcept { adj_ = 1.0; }
170
176 inline void set_zero_adjoint() noexcept final { adj_ = 0.0; }
177
187 friend std::ostream& operator<<(std::ostream& os, const vari_value<T>* v) {
188 return os << v->val_ << ":" << v->adj_;
189 }
190
191 private:
192 template <typename, typename>
193 friend class var_value;
194};
195
196// For backwards compatability the default is double
198
205template <typename T, typename = void>
207
214template <typename Derived>
216 private:
222 vari_view_eigen() = default;
223 friend Derived;
224
228 inline Derived& derived() { return static_cast<Derived&>(*this); }
232 inline const Derived& derived() const {
233 return static_cast<const Derived&>(*this);
234 }
235
236 public:
244 inline auto block(Eigen::Index start_row, Eigen::Index start_col,
245 Eigen::Index num_rows, Eigen::Index num_cols) const {
246 using inner_type = decltype(
247 derived().val_.block(start_row, start_col, num_rows, num_cols));
249 derived().val_.block(start_row, start_col, num_rows, num_cols),
250 derived().adj_.block(start_row, start_col, num_rows, num_cols));
251 }
252 inline auto block(Eigen::Index start_row, Eigen::Index start_col,
253 Eigen::Index num_rows, Eigen::Index num_cols) {
254 using inner_type = decltype(
255 derived().val_.block(start_row, start_col, num_rows, num_cols));
257 derived().val_.block(start_row, start_col, num_rows, num_cols),
258 derived().adj_.block(start_row, start_col, num_rows, num_cols));
259 }
260
265 inline auto head(Eigen::Index n) const {
266 using inner_type = decltype(derived().val_.head(n));
267 return vari_view<inner_type>(derived().val_.head(n),
268 derived().adj_.head(n));
269 }
270 inline auto head(Eigen::Index n) {
271 using inner_type = decltype(derived().val_.head(n));
272 return vari_view<inner_type>(derived().val_.head(n),
273 derived().adj_.head(n));
274 }
275
280 inline auto tail(Eigen::Index n) const {
281 using inner_type = decltype(derived().val_.tail(n));
282 return vari_view<inner_type>(derived().val_.tail(n),
283 derived().adj_.tail(n));
284 }
285 inline auto tail(Eigen::Index n) {
286 using inner_type = decltype(derived().val_.tail(n));
287 return vari_view<inner_type>(derived().val_.tail(n),
288 derived().adj_.tail(n));
289 }
290
296 inline auto segment(Eigen::Index i, Eigen::Index n) const {
297 using inner_type = decltype(derived().val_.segment(i, n));
298 return vari_view<inner_type>(derived().val_.segment(i, n),
299 derived().adj_.segment(i, n));
300 }
301 inline auto segment(Eigen::Index i, Eigen::Index n) {
302 using inner_type = decltype(derived().val_.segment(i, n));
303 return vari_view<inner_type>(derived().val_.segment(i, n),
304 derived().adj_.segment(i, n));
305 }
306
310 inline auto transpose() const {
311 using inner_type = decltype(derived().val_.transpose());
312 return vari_view<inner_type>(derived().val_.transpose(),
313 derived().adj_.transpose());
314 }
315 inline auto transpose() {
316 using inner_type = decltype(derived().val_.transpose());
317 return vari_view<inner_type>(derived().val_.transpose(),
318 derived().adj_.transpose());
319 }
320
325 inline auto row(Eigen::Index i) const {
326 using inner_type = decltype(derived().val_.row(i));
327 return vari_view<inner_type>(derived().val_.row(i), derived().adj_.row(i));
328 }
329 inline auto row(Eigen::Index i) {
330 using inner_type = decltype(derived().val_.row(i));
331 return vari_view<inner_type>(derived().val_.row(i), derived().adj_.row(i));
332 }
333
338 inline auto col(Eigen::Index i) const {
339 using inner_type = decltype(derived().val_.col(i));
340 return vari_view<inner_type>(derived().val_.col(i), derived().adj_.col(i));
341 }
342 inline auto col(Eigen::Index i) {
343 using inner_type = decltype(derived().val_.col(i));
344 return vari_view<inner_type>(derived().val_.col(i), derived().adj_.col(i));
345 }
346
351 inline auto diagonal() const {
352 using inner_type = decltype(derived().val_.diagonal());
353 return vari_view<inner_type>(derived().val_.diagonal(),
354 derived().adj_.diagonal());
355 }
356 inline auto diagonal() {
357 using inner_type = decltype(derived().val_.diagonal());
358 return vari_view<inner_type>(derived().val_.diagonal(),
359 derived().adj_.diagonal());
360 }
361
367 inline auto coeff(Eigen::Index i, Eigen::Index j) const {
368 return vari_value<double>(derived().val_.coeffRef(i, j),
369 derived().adj_.coeffRef(i, j));
370 }
371 inline auto coeff(Eigen::Index i, Eigen::Index j) {
372 return vari_value<double>(derived().val_.coeffRef(i, j),
373 derived().adj_.coeffRef(i, j));
374 }
375
380 inline auto coeff(Eigen::Index i) const {
381 return vari_value<double>(derived().val_.coeffRef(i),
382 derived().adj_.coeffRef(i));
383 }
384 inline auto coeff(Eigen::Index i) {
385 return vari_value<double>(derived().val_.coeffRef(i),
386 derived().adj_.coeffRef(i));
387 }
388
393 inline auto operator()(Eigen::Index i) const { return this->coeff(i); }
394 inline auto operator()(Eigen::Index i) { return this->coeff(i); }
395
401 inline auto operator()(Eigen::Index i, Eigen::Index j) const {
402 return this->coeff(i, j);
403 }
404 inline auto operator()(Eigen::Index i, Eigen::Index j) {
405 return this->coeff(i, j);
406 }
407
411 inline auto rowwise_reverse() const {
412 using inner_type = decltype(derived().val_.rowwise().reverse());
413 return vari_view<inner_type>(derived().val_.rowwise().reverse(),
414 derived().adj_.rowwise().reverse());
415 }
416 inline auto rowwise_reverse() {
417 using inner_type = decltype(derived().val_.rowwise().reverse());
418 return vari_view<inner_type>(derived().val_.rowwise().reverse(),
419 derived().adj_.rowwise().reverse());
420 }
421
425 inline auto colwise_reverse() const {
426 using inner_type = decltype(derived().val_.colwise().reverse());
427 return vari_view<inner_type>(derived().val_.colwise().reverse(),
428 derived().adj_.colwise().reverse());
429 }
430 inline auto colwise_reverse() {
431 using inner_type = decltype(derived().val_.colwise().reverse());
432 return vari_view<inner_type>(derived().val_.colwise().reverse(),
433 derived().adj_.colwise().reverse());
434 }
435
440 inline auto reverse() const {
441 using inner_type = decltype(derived().val_.reverse());
442 return vari_view<inner_type>(derived().val_.reverse(),
443 derived().adj_.reverse());
444 }
445 inline auto reverse() {
446 using inner_type = decltype(derived().val_.reverse());
447 return vari_view<inner_type>(derived().val_.reverse(),
448 derived().adj_.reverse());
449 }
450
455 inline auto topRows(Eigen::Index n) const {
456 using inner_type = decltype(derived().val_.topRows(n));
457 return vari_view<inner_type>(derived().val_.topRows(n),
458 derived().adj_.topRows(n));
459 }
460 inline auto topRows(Eigen::Index n) {
461 using inner_type = decltype(derived().val_.topRows(n));
462 return vari_view<inner_type>(derived().val_.topRows(n),
463 derived().adj_.topRows(n));
464 }
465
470 inline auto bottomRows(Eigen::Index n) const {
471 using inner_type = decltype(derived().val_.bottomRows(n));
472 return vari_view<inner_type>(derived().val_.bottomRows(n),
473 derived().adj_.bottomRows(n));
474 }
475 inline auto bottomRows(Eigen::Index n) {
476 using inner_type = decltype(derived().val_.bottomRows(n));
477 return vari_view<inner_type>(derived().val_.bottomRows(n),
478 derived().adj_.bottomRows(n));
479 }
480
486 inline auto middleRows(Eigen::Index start_row, Eigen::Index n) const {
487 using inner_type = decltype(derived().val_.middleRows(start_row, n));
488 return vari_view<inner_type>(derived().val_.middleRows(start_row, n),
489 derived().adj_.middleRows(start_row, n));
490 }
491 inline auto middleRows(Eigen::Index start_row, Eigen::Index n) {
492 using inner_type = decltype(derived().val_.middleRows(start_row, n));
493 return vari_view<inner_type>(derived().val_.middleRows(start_row, n),
494 derived().adj_.middleRows(start_row, n));
495 }
496
501 inline auto leftCols(Eigen::Index n) const {
502 using inner_type = decltype(derived().val_.leftCols(n));
503 return vari_view<inner_type>(derived().val_.leftCols(n),
504 derived().adj_.leftCols(n));
505 }
506 inline auto leftCols(Eigen::Index n) {
507 using inner_type = decltype(derived().val_.leftCols(n));
508 return vari_view<inner_type>(derived().val_.leftCols(n),
509 derived().adj_.leftCols(n));
510 }
511
516 inline auto rightCols(Eigen::Index n) const {
517 using inner_type = decltype(derived().val_.rightCols(n));
518 return vari_view<inner_type>(derived().val_.rightCols(n),
519 derived().adj_.rightCols(n));
520 }
521 inline auto rightCols(Eigen::Index n) {
522 using inner_type = decltype(derived().val_.rightCols(n));
523 return vari_view<inner_type>(derived().val_.rightCols(n),
524 derived().adj_.rightCols(n));
525 }
526
532 inline auto middleCols(Eigen::Index start_col, Eigen::Index n) const {
533 using inner_type = decltype(derived().val_.middleCols(start_col, n));
534 return vari_view<inner_type>(derived().val_.middleCols(start_col, n),
535 derived().adj_.middleCols(start_col, n));
536 }
537 inline auto middleCols(Eigen::Index start_col, Eigen::Index n) {
538 using inner_type = decltype(derived().val_.middleCols(start_col, n));
539 return vari_view<inner_type>(derived().val_.middleCols(start_col, n),
540 derived().adj_.middleCols(start_col, n));
541 }
542
546 inline auto array() const {
547 using inner_type = decltype(derived().val_.array());
548 return vari_view<inner_type>(derived().val_.array(),
549 derived().adj_.array());
550 }
551 inline auto array() {
552 using inner_type = decltype(derived().val_.array());
553 return vari_view<inner_type>(derived().val_.array(),
554 derived().adj_.array());
555 }
556
560 inline auto matrix() const {
561 using inner_type = decltype(derived().val_.matrix());
562 return vari_view<inner_type>(derived().val_.matrix(),
563 derived().adj_.matrix());
564 }
565 inline auto matrix() {
566 using inner_type = decltype(derived().val_.matrix());
567 return vari_view<inner_type>(derived().val_.matrix(),
568 derived().adj_.matrix());
569 }
570
574 inline Eigen::Index rows() const { return derived().val_.rows(); }
578 inline Eigen::Index cols() const { return derived().val_.cols(); }
582 inline Eigen::Index size() const { return derived().val_.size(); }
583};
584
585template <typename T>
588 final : public vari_base,
589 public vari_view_eigen<vari_view<T, require_not_plain_type_t<T>>> {
590 public:
592 using value_type = std::decay_t<T>; // The underlying type for this class
596 static constexpr int RowsAtCompileTime = PlainObject::RowsAtCompileTime;
600 static constexpr int ColsAtCompileTime = PlainObject::ColsAtCompileTime;
601
604 template <typename S, typename K,
607 vari_view(const S& val, const K& adj) noexcept : val_(val), adj_(adj) {}
608
614 inline const auto& val() const noexcept { return val_; }
615 inline auto& val_op() noexcept { return val_; }
616
625 inline auto& adj() noexcept { return adj_; }
626 inline auto& adj() const noexcept { return adj_; }
627 inline auto& adj_op() noexcept { return adj_; }
628
630 void chain() {}
631};
632
644template <typename T>
646 : public vari_base,
647 public vari_view_eigen<vari_value<
648 T, require_all_t<is_plain_type<T>, is_eigen_dense_base<T>>>> {
649 public:
654 using value_type = PlainObject; // The underlying type for this class
655 using eigen_scalar = value_type_t<PlainObject>; // A floating point type
660 static constexpr int RowsAtCompileTime = PlainObject::RowsAtCompileTime;
664 static constexpr int ColsAtCompileTime = PlainObject::ColsAtCompileTime;
665
670
676
688 template <typename S, require_assignable_t<T, S>* = nullptr>
689 explicit vari_value(const S& x)
690 : val_(x),
691 adj_((RowsAtCompileTime == 1 && S::ColsAtCompileTime == 1)
692 || (ColsAtCompileTime == 1 && S::RowsAtCompileTime == 1)
693 ? x.cols()
694 : x.rows(),
695 (RowsAtCompileTime == 1 && S::ColsAtCompileTime == 1)
696 || (ColsAtCompileTime == 1 && S::RowsAtCompileTime == 1)
697 ? x.rows()
698 : x.cols()) {
699 adj_.setZero();
701 }
702
718 template <typename S, require_assignable_t<T, S>* = nullptr>
719 vari_value(const S& x, bool stacked)
720 : val_(x),
721 adj_((RowsAtCompileTime == 1 && S::ColsAtCompileTime == 1)
722 || (ColsAtCompileTime == 1 && S::RowsAtCompileTime == 1)
723 ? x.cols()
724 : x.rows(),
725 (RowsAtCompileTime == 1 && S::ColsAtCompileTime == 1)
726 || (ColsAtCompileTime == 1 && S::RowsAtCompileTime == 1)
727 ? x.rows()
728 : x.cols()) {
729 adj_.setZero();
730 if (stacked) {
731 ChainableStack::instance_->var_stack_.push_back(this);
732 } else {
734 }
735 }
736
749 template <typename S, typename K, require_assignable_t<T, S>* = nullptr,
750 require_assignable_t<T, K>* = nullptr>
751 explicit vari_value(const S& val, const K& adj) : val_(val), adj_(adj) {
753 }
754
755 protected:
756 template <typename S, require_not_same_t<T, S>* = nullptr>
757 explicit vari_value(const vari_value<S>* x) : val_(x->val_), adj_(x->adj_) {}
758
759 public:
765 inline const auto& val() const noexcept { return val_; }
766 inline auto& val_op() noexcept { return val_; }
767
776 inline auto& adj() noexcept { return adj_; }
777 inline auto& adj() const noexcept { return adj_; }
778 inline auto& adj_op() noexcept { return adj_; }
779
780 virtual void chain() {}
787 inline void init_dependent() { adj_.setOnes(); }
788
794 inline void set_zero_adjoint() final { adj_.setZero(); }
795
805 friend std::ostream& operator<<(std::ostream& os, const vari_value<T>* v) {
806 return os << "val: \n" << v->val_ << " \nadj: \n" << v->adj_;
807 }
808
809 private:
810 template <typename, typename>
811 friend class var_value;
812};
813
825template <typename T>
827 public:
828 using PlainObject = plain_type_t<T>; // Base type of Eigen class
829 using value_type = PlainObject; // vari's adj_ and val_ member type
834 static constexpr int RowsAtCompileTime = T::RowsAtCompileTime;
838 static constexpr int ColsAtCompileTime = T::ColsAtCompileTime;
839
849
864 template <typename S, require_convertible_t<S&, T>* = nullptr>
865 explicit vari_value(S&& x)
866 : val_(std::forward<S>(x)),
867 adj_(val_.rows(), val_.cols(), val_.nonZeros(), val_.outerIndexPtr(),
868 val_.innerIndexPtr(),
869 arena_matrix<Eigen::VectorXd>(val_.nonZeros()).setZero().data(),
870 val_.innerNonZeroPtr()) {
871 ChainableStack::instance_->var_stack_.push_back(this);
872 }
873
875 const arena_matrix<PlainObject>& adj)
876 : val_(val), adj_(adj) {
877 ChainableStack::instance_->var_stack_.push_back(this);
878 }
879
897 template <typename S, require_convertible_t<S&, T>* = nullptr>
898 vari_value(S&& x, bool stacked)
899 : val_(std::forward<S>(x)),
900 adj_(val_.rows(), val_.cols(), val_.nonZeros(), val_.outerIndexPtr(),
901 val_.innerIndexPtr(),
902 arena_matrix<Eigen::VectorXd>(val_.nonZeros()).setZero().data(),
903 val_.innerNonZeroPtr()) {
904 if (stacked) {
905 ChainableStack::instance_->var_stack_.push_back(this);
906 } else {
908 }
909 }
910
914 Eigen::Index rows() const { return val_.rows(); }
918 Eigen::Index cols() const { return val_.cols(); }
922 Eigen::Index size() const { return val_.size(); }
923
929 inline const auto& val() const { return val_; }
930 inline auto& val_op() { return val_; }
931
940 inline auto& adj() { return adj_; }
941 inline auto& adj() const { return adj_; }
942 inline auto& adj_op() { return adj_; }
943
944 void chain() {}
951 inline void init_dependent() {
952 std::fill(adj_.valuePtr(), adj_.valuePtr() + adj_.nonZeros(), 1.0);
953 }
954
960 inline void set_zero_adjoint() noexcept final {
961 std::fill(adj_.valuePtr(), adj_.valuePtr() + adj_.nonZeros(), 0.0);
962 }
963
973 friend std::ostream& operator<<(std::ostream& os, const vari_value<T>* v) {
974 return os << "val: \n" << v->val_ << " \nadj: \n" << v->adj_;
975 }
976
977 private:
978 template <typename, typename>
979 friend class var_value;
980};
981
982} // namespace math
983} // namespace stan
984#endif
Equivalent to Eigen::Matrix, except that the data is stored on AD stack.
void * alloc(size_t len)
Return a newly allocated block of memory of the appropriate size managed by the stack allocator.
virtual void chain()=0
Apply the chain rule to this variable based on the variables on which it depends.
virtual void set_zero_adjoint()=0
Abstract base class that all vari_value and it's derived classes inherit.
Definition vari.hpp:28
const auto & val() const noexcept
Return a constant reference to the value of this vari.
Definition vari.hpp:765
friend std::ostream & operator<<(std::ostream &os, const vari_value< T > *v)
Insertion operator for vari.
Definition vari.hpp:805
vari_value(const S &val, const K &adj)
Construct a dense Eigen variable implementation from a preconstructed values and adjoints.
Definition vari.hpp:751
void init_dependent()
Initialize the adjoint for this (dependent) variable to 1.
Definition vari.hpp:787
arena_matrix< PlainObject > adj_
The adjoint of this variable, which is the partial derivative of this variable with respect to the ro...
Definition vari.hpp:675
plain_type_t< T > PlainObject
PlainObject represents a user constructible type such as Matrix or Array
Definition vari.hpp:653
virtual void chain()
Apply the chain rule to this variable based on the variables on which it depends.
Definition vari.hpp:780
vari_value(const S &x)
Construct a dense Eigen variable implementation from a value.
Definition vari.hpp:689
void set_zero_adjoint() final
Set the adjoint value of this variable to 0.
Definition vari.hpp:794
auto & adj() noexcept
Return a reference to the derivative of the root expression with respect to this expression.
Definition vari.hpp:776
vari_value(const S &x, bool stacked)
Construct a dense Eigen variable implementation from a value.
Definition vari.hpp:719
Eigen::Index rows() const
Return the number of rows for this class's val_ member.
Definition vari.hpp:914
Eigen::Index size() const
Return the size of this class's val_ member.
Definition vari.hpp:922
arena_matrix< PlainObject > val_
The value of this variable.
Definition vari.hpp:843
void init_dependent()
Initialize the adjoint for this (dependent) variable to 1.
Definition vari.hpp:951
auto & adj()
Return a reference to the derivative of the root expression with respect to this expression.
Definition vari.hpp:940
vari_value(const arena_matrix< PlainObject > &val, const arena_matrix< PlainObject > &adj)
Definition vari.hpp:874
vari_value(S &&x, bool stacked)
Construct an sparse Eigen variable implementation from a value.
Definition vari.hpp:898
Eigen::Index cols() const
Return the number of columns for this class's val_ member.
Definition vari.hpp:918
arena_matrix< PlainObject > adj_
The adjoint of this variable, which is the partial derivative of this variable with respect to the ro...
Definition vari.hpp:848
vari_value(S &&x)
Construct a variable implementation from a value.
Definition vari.hpp:865
const auto & val() const
Return a constant reference to the value of this vari.
Definition vari.hpp:929
typename arena_matrix< PlainObject >::InnerIterator InnerIterator
Definition vari.hpp:830
friend std::ostream & operator<<(std::ostream &os, const vari_value< T > *v)
Insertion operator for vari.
Definition vari.hpp:973
void chain()
Apply the chain rule to this variable based on the variables on which it depends.
Definition vari.hpp:944
void set_zero_adjoint() noexcept final
Set the adjoint value of this variable to 0.
Definition vari.hpp:960
void init_dependent() noexcept
Initialize the adjoint for this (dependent) variable to 1.
Definition vari.hpp:169
void set_zero_adjoint() noexcept final
Set the adjoint value of this variable to 0.
Definition vari.hpp:176
const auto & val() const
Return a constant reference to the value of this vari.
Definition vari.hpp:139
void chain()
Apply the chain rule to this variable based on the variables on which it depends.
Definition vari.hpp:161
auto & adj() const
Return a reference of the derivative of the root expression with respect to this expression.
Definition vari.hpp:149
vari_value(S x) noexcept
Construct a variable implementation from a value.
Definition vari.hpp:106
friend std::ostream & operator<<(std::ostream &os, const vari_value< T > *v)
Insertion operator for vari.
Definition vari.hpp:187
const value_type val_
The value of this variable.
Definition vari.hpp:85
auto & adj()
Return a reference to the derivative of the root expression with respect to this expression.
Definition vari.hpp:159
vari_value(S x, bool stacked) noexcept
Construct a variable implementation from a value.
Definition vari.hpp:126
auto & adj() noexcept
Return a reference to the derivative of the root expression with respect to this expression.
Definition vari.hpp:625
void chain()
Apply the chain rule to this variable based on the variables on which it depends.
Definition vari.hpp:630
const auto & val() const noexcept
Return a constant reference to the value of this vari.
Definition vari.hpp:614
auto row(Eigen::Index i) const
View row of eigen matrices.
Definition vari.hpp:325
auto rowwise_reverse() const
Return an expression that operates on the rows of the matrix vari
Definition vari.hpp:411
auto middleRows(Eigen::Index start_row, Eigen::Index n) const
Return a block consisting of rows in the middle.
Definition vari.hpp:486
auto col(Eigen::Index i) const
View column of eigen matrices.
Definition vari.hpp:338
auto middleRows(Eigen::Index start_row, Eigen::Index n)
Definition vari.hpp:491
auto array() const
Return an Array expression.
Definition vari.hpp:546
auto diagonal() const
View diagonal of eigen matrices.
Definition vari.hpp:351
auto segment(Eigen::Index i, Eigen::Index n)
Definition vari.hpp:301
auto colwise_reverse() const
Return an expression that operates on the columns of the matrix vari
Definition vari.hpp:425
Eigen::Index rows() const
Return the number of rows for this class's val_ member.
Definition vari.hpp:574
auto topRows(Eigen::Index n)
Definition vari.hpp:460
const Derived & derived() const
Helper function to return a constant reference to the derived type.
Definition vari.hpp:232
auto tail(Eigen::Index n)
Definition vari.hpp:285
auto matrix() const
Return a Matrix expression.
Definition vari.hpp:560
auto coeff(Eigen::Index i) const
Get coefficient of eigen matrices.
Definition vari.hpp:380
auto head(Eigen::Index n)
Definition vari.hpp:270
auto bottomRows(Eigen::Index n)
Definition vari.hpp:475
auto block(Eigen::Index start_row, Eigen::Index start_col, Eigen::Index num_rows, Eigen::Index num_cols) const
A block view of the underlying Eigen matrices.
Definition vari.hpp:244
auto coeff(Eigen::Index i, Eigen::Index j) const
Get coefficient of eigen matrices.
Definition vari.hpp:367
auto transpose() const
View transpose of eigen matrix.
Definition vari.hpp:310
auto operator()(Eigen::Index i)
Definition vari.hpp:394
auto tail(Eigen::Index n) const
View of the tail of the Eigen vector types.
Definition vari.hpp:280
auto topRows(Eigen::Index n) const
Return a block consisting of the top rows.
Definition vari.hpp:455
auto row(Eigen::Index i)
Definition vari.hpp:329
auto head(Eigen::Index n) const
View of the head of Eigen vector types.
Definition vari.hpp:265
auto segment(Eigen::Index i, Eigen::Index n) const
View block of N elements starting at position i
Definition vari.hpp:296
auto rightCols(Eigen::Index n)
Definition vari.hpp:521
auto block(Eigen::Index start_row, Eigen::Index start_col, Eigen::Index num_rows, Eigen::Index num_cols)
Definition vari.hpp:252
auto leftCols(Eigen::Index n)
Definition vari.hpp:506
Eigen::Index size() const
Return the size of this class's val_ member.
Definition vari.hpp:582
auto bottomRows(Eigen::Index n) const
Return a block consisting of the bottom rows.
Definition vari.hpp:470
auto reverse() const
Return an expression to reverse the order of the coefficients inside of a vari matrix.
Definition vari.hpp:440
auto col(Eigen::Index i)
Definition vari.hpp:342
Eigen::Index cols() const
Return the number of columns for this class's val_ member.
Definition vari.hpp:578
auto operator()(Eigen::Index i, Eigen::Index j)
Definition vari.hpp:404
auto coeff(Eigen::Index i)
Definition vari.hpp:384
auto operator()(Eigen::Index i) const
Get coefficient of eigen matrices.
Definition vari.hpp:393
auto middleCols(Eigen::Index start_col, Eigen::Index n)
Definition vari.hpp:537
auto coeff(Eigen::Index i, Eigen::Index j)
Definition vari.hpp:371
vari_view_eigen()=default
Making the base constructor private while making the derived class a friend help's catch if derived t...
auto leftCols(Eigen::Index n) const
Return a block consisting of the left-most columns.
Definition vari.hpp:501
auto middleCols(Eigen::Index start_col, Eigen::Index n) const
Return a block consisting of columns in the middle.
Definition vari.hpp:532
auto operator()(Eigen::Index i, Eigen::Index j) const
Get coefficient of eigen matrices.
Definition vari.hpp:401
auto rightCols(Eigen::Index n) const
Return a block consisting of the right-most columns.
Definition vari.hpp:516
Derived & derived()
Helper function to return a reference to the derived type.
Definition vari.hpp:228
This struct is follows the CRTP for methods common to vari_view<> and vari_value<Matrix>.
Definition vari.hpp:215
A vari_view is used to read from a slice of a vari_value with an inner eigen type.
Definition vari.hpp:206
require_t< std::is_assignable< std::decay_t< T >, std::decay_t< S > > > require_assignable_t
Require types T and S satisfies std::is_assignable.
require_t< is_eigen_sparse_base< std::decay_t< T > > > require_eigen_sparse_base_t
Require type satisfies is_eigen_sparse_base.
int64_t cols(const T_x &x)
Returns the number of columns in the specified kernel generator expression.
Definition cols.hpp:21
int64_t rows(const T_x &x)
Returns the number of rows in the specified kernel generator expression.
Definition rows.hpp:22
std::is_same< std::decay_t< S >, plain_type_t< S > > is_plain_type
Checks whether the template type T is an assignable type.
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
std::integral_constant< bool, B > bool_constant
Alias for structs used for wraps a static constant of bool.
(Expert) Numerical traits for algorithmic differentiation variables.
typename plain_type< T >::type plain_type_t
std::enable_if_t< Check::value > require_t
If condition is true, template is enabled.
std::enable_if_t< math::conjunction< Checks... >::value > require_all_t
If all conditions are true, template is enabled Returns a type void if all conditions are true and ot...
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
STL namespace.
Checks whether type T is derived from Eigen::DenseBase.
Check if type derives from EigenBase
Definition is_eigen.hpp:21
static thread_local AutodiffStackStorage * instance_