19template <
typename Scalar>
33 stack.emplace_back(root.
get());
34 while (!stack.empty()) {
35 auto node = stack.back();
38 for (
auto&
arg : node->args) {
40 if (
arg !=
nullptr && ++
arg->incoming_edges == 1) {
41 stack.push_back(
arg.get());
53 stack.emplace_back(root.
get());
54 while (!stack.empty()) {
55 auto node = stack.back();
58 list.emplace_back(node);
60 for (
auto&
arg : node->args) {
62 if (
arg !=
nullptr && --
arg->incoming_edges == 0) {
63 stack.push_back(
arg.get());
76template <
typename Scalar>
79 for (
auto& node : list | std::views::reverse) {
80 auto& lhs = node->args[0];
81 auto& rhs = node->args[1];
84 node->val = node->value(lhs->val, rhs ? rhs->val : Scalar(0));
auto arg(const Char *name, const T &arg) -> detail::named_arg< Char, T >
Returns a named argument to be used in a formatting function.
Definition base.h:2846
constexpr T * get() const noexcept
Returns the internal pointer.
Definition intrusive_shared_ptr.hpp:178
wpi::util::SmallVector< T > small_vector
Definition small_vector.hpp:10
Definition expression_graph.hpp:11
void update_values(const gch::small_vector< Expression< Scalar > * > &list)
Update the values of all nodes in this graph based on the values of their dependent nodes.
Definition expression_graph.hpp:77
gch::small_vector< Expression< Scalar > * > topological_sort(const ExpressionPtr< Scalar > &root)
Generate a topological sort of an expression graph from parent to child.
Definition expression_graph.hpp:20
IntrusiveSharedPtr< Expression< Scalar > > ExpressionPtr
Typedef for intrusive shared pointer to Expression.
Definition expression.hpp:43
@ CONSTANT
The expression is a constant.
Definition expression_type.hpp:20
An autodiff expression node.
Definition expression.hpp:89
virtual ExpressionType type() const =0
Returns the type of this expression (constant, linear, quadratic, or nonlinear).