@@ -678,11 +678,9 @@ class vari_value<T, require_all_t<is_plain_type<T>, is_eigen_dense_base<T>>>
678678 * Construct a dense Eigen variable implementation from a value. The
679679 * adjoint is initialized to zero.
680680 *
681- * All constructed variables are added to the stack. Variables
681+ * All constructed variables are added to the no chain stack. Variables
682682 * should be constructed before variables on which they depend
683- * to insure proper partial derivative propagation. During
684- * derivative propagation, the chain() method of each variable
685- * will be called in the reverse order of construction.
683+ * to insure proper partial derivative propagation.
686684 *
687685 * @tparam S A dense Eigen type that is convertible to `value_type`
688686 * @param x Value of the constructed variable.
@@ -699,7 +697,7 @@ class vari_value<T, require_all_t<is_plain_type<T>, is_eigen_dense_base<T>>>
699697 ? x.rows()
700698 : x.cols()) {
701699 adj_.setZero ();
702- ChainableStack::instance_->var_stack_ .push_back (this );
700+ ChainableStack::instance_->var_nochain_stack_ .push_back (this );
703701 }
704702
705703 /* *
@@ -736,6 +734,24 @@ class vari_value<T, require_all_t<is_plain_type<T>, is_eigen_dense_base<T>>>
736734 }
737735 }
738736
737+ /* *
738+ * Construct a dense Eigen variable implementation from a
739+ * preconstructed values and adjoints.
740+ *
741+ * All constructed variables are not added to the stack. Variables
742+ * should be constructed before variables on which they depend
743+ * to insure proper partial derivative propagation.
744+ * @tparam S A dense Eigen type that is convertible to `value_type`
745+ * @tparam K A dense Eigen type that is convertible to `value_type`
746+ * @param val Matrix of values
747+ * @param adj Matrix of adjoints
748+ */
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) {
752+ ChainableStack::instance_->var_nochain_stack_ .push_back (this );
753+ }
754+
739755 protected:
740756 template <typename S, require_not_same_t <T, S>* = nullptr >
741757 explicit vari_value (const vari_value<S>* x) : val_(x->val_), adj_(x->adj_) {}
0 commit comments