47template <
typename Scalar>
51 diff.
compute(func_value.node());
52 return diff.
coeff(arg.node());
64template <
typename ArgType>
75 ArgType::ColsAtCompileTime, Eigen::ColMajor,
76 ArgType::MaxRowsAtCompileTime, ArgType::MaxColsAtCompileTime>;
96 return diff_->coeff(
arg_(row, col).node());
104 std::shared_ptr<const graph::node_differentiator<scalar_type>>
diff_;
118template <
typename Scalar,
typename ArgDerived>
120 const Eigen::MatrixBase<ArgDerived>& arg)
121 -> Eigen::CwiseNullaryOp<
124 ArgDerived>::result_type> {
126 std::is_same_v<typename ArgDerived::Scalar, variable<Scalar>>);
128 auto diff = std::make_shared<graph::node_differentiator<Scalar>>();
129 diff->compute(func_value.node());
132 ArgDerived>::result_type;
133 return result_type::NullaryExpr(arg.rows(), arg.cols(),
135 arg.derived(), std::move(diff)));
148template <
typename FuncValType,
typename ArgType>
154 static_assert(std::is_same_v<typename ArgType::Scalar, variable_type>);
161 Eigen::Matrix<
scalar_type, FuncValType::RowsAtCompileTime,
162 ArgType::RowsAtCompileTime, Eigen::ColMajor,
163 FuncValType::MaxRowsAtCompileTime, ArgType::MaxRowsAtCompileTime>;
185 .coeff(
arg_(col, 0).node());
193 std::shared_ptr<std::vector<graph::node_differentiator<scalar_type>>>
diff_;
207template <
typename FuncValType,
typename ArgType>
209 const Eigen::MatrixBase<FuncValType>& func_value,
210 const Eigen::MatrixBase<ArgType>& arg)
211 -> Eigen::CwiseNullaryOp<
214 ArgType>::result_type> {
215 using variable_type =
typename FuncValType::Scalar;
216 using scalar_type =
typename variable_type::scalar_type;
219 "differentiate function requires vectors as arguments.");
221 auto diff = std::make_shared<
222 std::vector<graph::node_differentiator<scalar_type>>>();
224 for (
index_type i = 0; i < func_value.size(); ++i) {
226 .compute(func_value(i, 0).node());
231 ArgType>::result_type;
232 return result_type::NullaryExpr(func_value.size(), arg.size(),
234 arg.derived(), std::move(diff)));
Definition of node class.
Class to compute differential coefficients for nodes in backward-mode automatic differentiation kubot...
void compute(const node_ptr< scalar_type > &top_node)
Compute differential coefficients.
auto coeff(const node_ptr< scalar_type > &node) const -> scalar_type
Get the differential coefficient of a node.
Class of functor to assign differential coefficients to matrices on the condition that a scalar-value...
typename ArgType::Scalar variable_type
Type of variables.
typename variable_type::scalar_type scalar_type
Type of scalars.
Eigen::Matrix< scalar_type, ArgType::RowsAtCompileTime, ArgType::ColsAtCompileTime, Eigen::ColMajor, ArgType::MaxRowsAtCompileTime, ArgType::MaxColsAtCompileTime > result_type
Type of resulting differential coefficients.
const ArgType & arg_
Matrix of variable.
differentiate_scalar_with_matrix_functor(const ArgType &arg, std::shared_ptr< const graph::node_differentiator< scalar_type > > diff)
Constructor.
auto operator()(index_type row, index_type col) const -> scalar_type
Get an element of differential coefficients.
std::shared_ptr< const graph::node_differentiator< scalar_type > > diff_
Differentiator.
Class of functor to assign differential coefficients to matrices on the condition that a vector-value...
Eigen::Matrix< scalar_type, FuncValType::RowsAtCompileTime, ArgType::RowsAtCompileTime, Eigen::ColMajor, FuncValType::MaxRowsAtCompileTime, ArgType::MaxRowsAtCompileTime > result_type
Type of resulting differential coefficients.
differentiate_vector_with_vector_functor(const ArgType &arg, std::shared_ptr< std::vector< graph::node_differentiator< scalar_type > > > diff)
Constructor.
const ArgType & arg_
Matrix of variable.
std::shared_ptr< std::vector< graph::node_differentiator< scalar_type > > > diff_
Differentiators.
auto operator()(index_type row, index_type col) const -> scalar_type
Get an element of differential coefficients.
typename FuncValType::Scalar variable_type
Type of variables.
typename variable_type::scalar_type scalar_type
Type of scalars.
Class of variables in backward-mode automatic differentiation kubota1998.
Definition of exceptions.
Definition of index_type type.
Definition of macros for logging.
Namespace of backward-mode automatic differentiation.
auto differentiate(const variable< Scalar > &func_value, const variable< Scalar > &arg) -> Scalar
Compute a differential coefficient.
Namespace of internal implementations.
std::ptrdiff_t index_type
Type of indices in this library.
auto safe_cast(const From &value) -> To
Cast safely.
Definition of node class.
Definition of NUM_COLLECT_PRECONDITION macro.
#define NUM_COLLECT_PRECONDITION(CONDITION,...)
Check whether a precondition is satisfied and throw an exception if not.
Definition of safe_cast function.