WPILibC++ 2027.0.0-alpha-3
Loading...
Searching...
No Matches
variable.hpp
Go to the documentation of this file.
1// Copyright (c) Sleipnir contributors
2
3#pragma once
4
5#include <algorithm>
6#include <concepts>
7#include <initializer_list>
8#include <source_location>
9#include <type_traits>
10#include <utility>
11#include <vector>
12
13#include <Eigen/Core>
14#include <gch/small_vector.hpp>
15
21
22#ifndef SLEIPNIR_DISABLE_DIAGNOSTICS
24#endif
25
26namespace slp {
27
28// Forward declarations for friend declarations in Variable
29namespace detail {
30class AdjointExpressionGraph;
31} // namespace detail
32template <int UpLo = Eigen::Lower | Eigen::Upper>
33 requires(UpLo == Eigen::Lower) || (UpLo == (Eigen::Lower | Eigen::Upper))
36
37/**
38 * An autodiff variable pointing to an expression node.
39 */
41 public:
42 /**
43 * Constructs a linear Variable with a value of zero.
44 */
45 Variable() = default;
46
47 /**
48 * Constructs an empty Variable.
49 */
50 explicit Variable(std::nullptr_t) : expr{nullptr} {}
51
52 /**
53 * Constructs a Variable from a floating point type.
54 *
55 * @param value The value of the Variable.
56 */
57 Variable(std::floating_point auto value) // NOLINT
58 : expr{detail::make_expression_ptr<detail::ConstExpression>(value)} {}
59
60 /**
61 * Constructs a Variable from an integral type.
62 *
63 * @param value The value of the Variable.
64 */
65 Variable(std::integral auto value) // NOLINT
66 : expr{detail::make_expression_ptr<detail::ConstExpression>(value)} {}
67
68 /**
69 * Constructs a Variable pointing to the specified expression.
70 *
71 * @param expr The autodiff variable.
72 */
73 explicit Variable(const detail::ExpressionPtr& expr) : expr{expr} {}
74
75 /**
76 * Constructs a Variable pointing to the specified expression.
77 *
78 * @param expr The autodiff variable.
79 */
80 explicit Variable(detail::ExpressionPtr&& expr) : expr{std::move(expr)} {}
81
82 /**
83 * Assignment operator for double.
84 *
85 * @param value The value of the Variable.
86 * @return This variable.
87 */
88 Variable& operator=(double value) {
90 m_graph_initialized = false;
91
92 return *this;
93 }
94
95 /**
96 * Sets Variable's internal value.
97 *
98 * @param value The value of the Variable.
99 */
100 void set_value(double value) {
101#ifndef SLEIPNIR_DISABLE_DIAGNOSTICS
102 // We only need to check the first argument since unary and binary operators
103 // both use it
104 if (expr->args[0] != nullptr) {
105 auto location = std::source_location::current();
107 stderr,
108 "WARNING: {}:{}: {}: Modified the value of a dependent variable",
109 location.file_name(), location.line(), location.function_name());
110 }
111#endif
112 expr->val = value;
113 }
114
115 /**
116 * Variable-Variable multiplication operator.
117 *
118 * @param lhs Operator left-hand side.
119 * @param rhs Operator right-hand side.
120 * @return Result of multiplication.
121 */
123 const Variable& rhs) {
124 return Variable{lhs.expr * rhs.expr};
125 }
126
127 /**
128 * Variable-Variable compound multiplication operator.
129 *
130 * @param rhs Operator right-hand side.
131 * @return Result of multiplication.
132 */
134 *this = *this * rhs;
135 return *this;
136 }
137
138 /**
139 * Variable-Variable division operator.
140 *
141 * @param lhs Operator left-hand side.
142 * @param rhs Operator right-hand side.
143 * @return Result of division.
144 */
146 const Variable& rhs) {
147 return Variable{lhs.expr / rhs.expr};
148 }
149
150 /**
151 * Variable-Variable compound division operator.
152 *
153 * @param rhs Operator right-hand side.
154 * @return Result of division.
155 */
157 *this = *this / rhs;
158 return *this;
159 }
160
161 /**
162 * Variable-Variable addition operator.
163 *
164 * @param lhs Operator left-hand side.
165 * @param rhs Operator right-hand side.
166 * @return Result of addition.
167 */
169 const Variable& rhs) {
170 return Variable{lhs.expr + rhs.expr};
171 }
172
173 /**
174 * Variable-Variable compound addition operator.
175 *
176 * @param rhs Operator right-hand side.
177 * @return Result of addition.
178 */
180 *this = *this + rhs;
181 return *this;
182 }
183
184 /**
185 * Variable-Variable subtraction operator.
186 *
187 * @param lhs Operator left-hand side.
188 * @param rhs Operator right-hand side.
189 * @return Result of subtraction.
190 */
192 const Variable& rhs) {
193 return Variable{lhs.expr - rhs.expr};
194 }
195
196 /**
197 * Variable-Variable compound subtraction operator.
198 *
199 * @param rhs Operator right-hand side.
200 * @return Result of subtraction.
201 */
203 *this = *this - rhs;
204 return *this;
205 }
206
207 /**
208 * Unary minus operator.
209 *
210 * @param lhs Operand for unary minus.
211 */
213 return Variable{-lhs.expr};
214 }
215
216 /**
217 * Unary plus operator.
218 *
219 * @param lhs Operand for unary plus.
220 */
222 return Variable{+lhs.expr};
223 }
224
225 /**
226 * Returns the value of this variable.
227 *
228 * @return The value of this variable.
229 */
230 double value() {
231 if (!m_graph_initialized) {
232 m_graph = detail::topological_sort(expr);
233 m_graph_initialized = true;
234 }
235 detail::update_values(m_graph);
236
237 return expr->val;
238 }
239
240 /**
241 * Returns the type of this expression (constant, linear, quadratic, or
242 * nonlinear).
243 *
244 * @return The type of this expression.
245 */
246 ExpressionType type() const { return expr->type(); }
247
248 private:
249 /// The expression node
252
253 /// Used to update the value of this variable based on the values of its
254 /// dependent variables
256
257 /// Used for lazy initialization of m_graph
258 bool m_graph_initialized = false;
259
260 friend SLEIPNIR_DLLEXPORT Variable abs(const Variable& x);
261 friend SLEIPNIR_DLLEXPORT Variable acos(const Variable& x);
262 friend SLEIPNIR_DLLEXPORT Variable asin(const Variable& x);
263 friend SLEIPNIR_DLLEXPORT Variable atan(const Variable& x);
265 const Variable& x);
266 friend SLEIPNIR_DLLEXPORT Variable cbrt(const Variable& x);
267 friend SLEIPNIR_DLLEXPORT Variable cos(const Variable& x);
268 friend SLEIPNIR_DLLEXPORT Variable cosh(const Variable& x);
269 friend SLEIPNIR_DLLEXPORT Variable erf(const Variable& x);
270 friend SLEIPNIR_DLLEXPORT Variable exp(const Variable& x);
272 const Variable& y);
273 friend SLEIPNIR_DLLEXPORT Variable log(const Variable& x);
274 friend SLEIPNIR_DLLEXPORT Variable log10(const Variable& x);
275 friend SLEIPNIR_DLLEXPORT Variable pow(const Variable& base,
276 const Variable& power);
277 friend SLEIPNIR_DLLEXPORT Variable sign(const Variable& x);
278 friend SLEIPNIR_DLLEXPORT Variable sin(const Variable& x);
279 friend SLEIPNIR_DLLEXPORT Variable sinh(const Variable& x);
280 friend SLEIPNIR_DLLEXPORT Variable sqrt(const Variable& x);
281 friend SLEIPNIR_DLLEXPORT Variable tan(const Variable& x);
282 friend SLEIPNIR_DLLEXPORT Variable tanh(const Variable& x);
283 friend SLEIPNIR_DLLEXPORT Variable hypot(const Variable& x, const Variable& y,
284 const Variable& z);
285
287 template <int UpLo>
288 requires(UpLo == Eigen::Lower) || (UpLo == (Eigen::Lower | Eigen::Upper))
291};
292
293/**
294 * std::abs() for Variables.
295 *
296 * @param x The argument.
297 */
299 return Variable{detail::abs(x.expr)};
300}
301
302/**
303 * std::acos() for Variables.
304 *
305 * @param x The argument.
306 */
308 return Variable{detail::acos(x.expr)};
309}
310
311/**
312 * std::asin() for Variables.
313 *
314 * @param x The argument.
315 */
317 return Variable{detail::asin(x.expr)};
318}
319
320/**
321 * std::atan() for Variables.
322 *
323 * @param x The argument.
324 */
326 return Variable{detail::atan(x.expr)};
327}
328
329/**
330 * std::atan2() for Variables.
331 *
332 * @param y The y argument.
333 * @param x The x argument.
334 */
336 return Variable{detail::atan2(y.expr, x.expr)};
337}
338
339/**
340 * std::cbrt() for Variables.
341 *
342 * @param x The argument.
343 */
345 return Variable{detail::cbrt(x.expr)};
346}
347
348/**
349 * std::cos() for Variables.
350 *
351 * @param x The argument.
352 */
354 return Variable{detail::cos(x.expr)};
355}
356
357/**
358 * std::cosh() for Variables.
359 *
360 * @param x The argument.
361 */
363 return Variable{detail::cosh(x.expr)};
364}
365
366/**
367 * std::erf() for Variables.
368 *
369 * @param x The argument.
370 */
372 return Variable{detail::erf(x.expr)};
373}
374
375/**
376 * std::exp() for Variables.
377 *
378 * @param x The argument.
379 */
381 return Variable{detail::exp(x.expr)};
382}
383
384/**
385 * std::hypot() for Variables.
386 *
387 * @param x The x argument.
388 * @param y The y argument.
389 */
391 return Variable{detail::hypot(x.expr, y.expr)};
392}
393
394/**
395 * std::pow() for Variables.
396 *
397 * @param base The base.
398 * @param power The power.
399 */
401 const Variable& power) {
402 return Variable{detail::pow(base.expr, power.expr)};
403}
404
405/**
406 * std::log() for Variables.
407 *
408 * @param x The argument.
409 */
411 return Variable{detail::log(x.expr)};
412}
413
414/**
415 * std::log10() for Variables.
416 *
417 * @param x The argument.
418 */
420 return Variable{detail::log10(x.expr)};
421}
422
423/**
424 * sign() for Variables.
425 *
426 * @param x The argument.
427 */
429 return Variable{detail::sign(x.expr)};
430}
431
432/**
433 * std::sin() for Variables.
434 *
435 * @param x The argument.
436 */
438 return Variable{detail::sin(x.expr)};
439}
440
441/**
442 * std::sinh() for Variables.
443 *
444 * @param x The argument.
445 */
447 return Variable{detail::sinh(x.expr)};
448}
449
450/**
451 * std::sqrt() for Variables.
452 *
453 * @param x The argument.
454 */
456 return Variable{detail::sqrt(x.expr)};
457}
458
459/**
460 * std::tan() for Variables.
461 *
462 * @param x The argument.
463 */
465 return Variable{detail::tan(x.expr)};
466}
467
468/**
469 * std::tanh() for Variables.
470 *
471 * @param x The argument.
472 */
474 return Variable{detail::tanh(x.expr)};
475}
476
477/**
478 * std::hypot() for Variables.
479 *
480 * @param x The x argument.
481 * @param y The y argument.
482 * @param z The z argument.
483 */
485 const Variable& z) {
486 return Variable{slp::sqrt(slp::pow(x, 2) + slp::pow(y, 2) + slp::pow(z, 2))};
487}
488
489/**
490 * Make a list of constraints.
491 *
492 * The standard form for equality constraints is c(x) = 0, and the standard form
493 * for inequality constraints is c(x) ≥ 0. This function takes constraints of
494 * the form lhs = rhs or lhs ≥ rhs and converts them to lhs - rhs = 0 or
495 * lhs - rhs ≥ 0.
496 *
497 * @param lhs Left-hand side.
498 * @param rhs Right-hand side.
499 */
500template <typename LHS, typename RHS>
501 requires(ScalarLike<LHS> || MatrixLike<LHS>) &&
505 gch::small_vector<Variable> constraints;
506
507 if constexpr (ScalarLike<LHS> && ScalarLike<RHS>) {
508 constraints.emplace_back(lhs - rhs);
509 } else if constexpr (ScalarLike<LHS> && MatrixLike<RHS>) {
510 constraints.reserve(rhs.rows() * rhs.cols());
511
512 for (int row = 0; row < rhs.rows(); ++row) {
513 for (int col = 0; col < rhs.cols(); ++col) {
514 // Make right-hand side zero
515 constraints.emplace_back(lhs - rhs(row, col));
516 }
517 }
518 } else if constexpr (MatrixLike<LHS> && ScalarLike<RHS>) {
519 constraints.reserve(lhs.rows() * lhs.cols());
520
521 for (int row = 0; row < lhs.rows(); ++row) {
522 for (int col = 0; col < lhs.cols(); ++col) {
523 // Make right-hand side zero
524 constraints.emplace_back(lhs(row, col) - rhs);
525 }
526 }
527 } else if constexpr (MatrixLike<LHS> && MatrixLike<RHS>) {
528 slp_assert(lhs.rows() == rhs.rows() && lhs.cols() == rhs.cols());
529 constraints.reserve(lhs.rows() * lhs.cols());
530
531 for (int row = 0; row < lhs.rows(); ++row) {
532 for (int col = 0; col < lhs.cols(); ++col) {
533 // Make right-hand side zero
534 constraints.emplace_back(lhs(row, col) - rhs(row, col));
535 }
536 }
537 }
538
539 return constraints;
540}
541
542/**
543 * A vector of equality constraints of the form cₑ(x) = 0.
544 */
546 /// A vector of scalar equality constraints.
548
549 /**
550 * Concatenates multiple equality constraints.
551 *
552 * @param equality_constraints The list of EqualityConstraints to concatenate.
553 */
555 std::initializer_list<EqualityConstraints> equality_constraints) {
556 for (const auto& elem : equality_constraints) {
557 constraints.insert(constraints.end(), elem.constraints.begin(),
558 elem.constraints.end());
559 }
560 }
561
562 /**
563 * Concatenates multiple equality constraints.
564 *
565 * This overload is for Python bindings only.
566 *
567 * @param equality_constraints The list of EqualityConstraints to concatenate.
568 */
570 const std::vector<EqualityConstraints>& equality_constraints) {
571 for (const auto& elem : equality_constraints) {
572 constraints.insert(constraints.end(), elem.constraints.begin(),
573 elem.constraints.end());
574 }
575 }
576
577 /**
578 * Constructs an equality constraint from a left and right side.
579 *
580 * The standard form for equality constraints is c(x) = 0. This function takes
581 * a constraint of the form lhs = rhs and converts it to lhs - rhs = 0.
582 *
583 * @param lhs Left-hand side.
584 * @param rhs Right-hand side.
585 */
586 template <typename LHS, typename RHS>
587 requires(ScalarLike<LHS> || MatrixLike<LHS>) &&
590 EqualityConstraints(LHS&& lhs, RHS&& rhs)
591 : constraints{make_constraints(lhs, rhs)} {}
592
593 /**
594 * Implicit conversion operator to bool.
595 */
596 operator bool() { // NOLINT
597 return std::ranges::all_of(constraints, [](auto& constraint) {
598 return constraint.value() == 0.0;
599 });
600 }
601};
602
603/**
604 * A vector of inequality constraints of the form cᵢ(x) ≥ 0.
605 */
607 /// A vector of scalar inequality constraints.
609
610 /**
611 * Concatenates multiple inequality constraints.
612 *
613 * @param inequality_constraints The list of InequalityConstraints to
614 * concatenate.
615 */
617 std::initializer_list<InequalityConstraints> inequality_constraints) {
618 for (const auto& elem : inequality_constraints) {
619 constraints.insert(constraints.end(), elem.constraints.begin(),
620 elem.constraints.end());
621 }
622 }
623
624 /**
625 * Concatenates multiple inequality constraints.
626 *
627 * This overload is for Python bindings only.
628 *
629 * @param inequality_constraints The list of InequalityConstraints to
630 * concatenate.
631 */
633 const std::vector<InequalityConstraints>& inequality_constraints) {
634 for (const auto& elem : inequality_constraints) {
635 constraints.insert(constraints.end(), elem.constraints.begin(),
636 elem.constraints.end());
637 }
638 }
639
640 /**
641 * Constructs an inequality constraint from a left and right side.
642 *
643 * The standard form for inequality constraints is c(x) ≥ 0. This function
644 * takes a constraints of the form lhs ≥ rhs and converts it to lhs - rhs ≥ 0.
645 *
646 * @param lhs Left-hand side.
647 * @param rhs Right-hand side.
648 */
649 template <typename LHS, typename RHS>
650 requires(ScalarLike<LHS> || MatrixLike<LHS>) &&
653 InequalityConstraints(LHS&& lhs, RHS&& rhs)
654 : constraints{make_constraints(lhs, rhs)} {}
655
656 /**
657 * Implicit conversion operator to bool.
658 */
659 operator bool() { // NOLINT
660 return std::ranges::all_of(constraints, [](auto& constraint) {
661 return constraint.value() >= 0.0;
662 });
663 }
664};
665
666/**
667 * Equality operator that returns an equality constraint for two Variables.
668 *
669 * @param lhs Left-hand side.
670 * @param rhs Left-hand side.
671 */
672template <typename LHS, typename RHS>
673 requires(ScalarLike<LHS> || MatrixLike<LHS>) &&
674 (ScalarLike<RHS> || MatrixLike<RHS>) &&
675 (SleipnirType<LHS> || SleipnirType<RHS>)
676EqualityConstraints operator==(LHS&& lhs, RHS&& rhs) {
677 return EqualityConstraints{lhs, rhs};
678}
679
680/**
681 * Less-than comparison operator that returns an inequality constraint for two
682 * Variables.
683 *
684 * @param lhs Left-hand side.
685 * @param rhs Left-hand side.
686 */
687template <typename LHS, typename RHS>
688 requires(ScalarLike<LHS> || MatrixLike<LHS>) &&
689 (ScalarLike<RHS> || MatrixLike<RHS>) &&
690 (SleipnirType<LHS> || SleipnirType<RHS>)
691InequalityConstraints operator<(LHS&& lhs, RHS&& rhs) {
692 return rhs >= lhs;
693}
694
695/**
696 * Less-than-or-equal-to comparison operator that returns an inequality
697 * constraint for two Variables.
698 *
699 * @param lhs Left-hand side.
700 * @param rhs Left-hand side.
701 */
702template <typename LHS, typename RHS>
703 requires(ScalarLike<LHS> || MatrixLike<LHS>) &&
704 (ScalarLike<RHS> || MatrixLike<RHS>) &&
705 (SleipnirType<LHS> || SleipnirType<RHS>)
706InequalityConstraints operator<=(LHS&& lhs, RHS&& rhs) {
707 return rhs >= lhs;
708}
709
710/**
711 * Greater-than comparison operator that returns an inequality constraint for
712 * two Variables.
713 *
714 * @param lhs Left-hand side.
715 * @param rhs Left-hand side.
716 */
717template <typename LHS, typename RHS>
718 requires(ScalarLike<LHS> || MatrixLike<LHS>) &&
719 (ScalarLike<RHS> || MatrixLike<RHS>) &&
720 (SleipnirType<LHS> || SleipnirType<RHS>)
721InequalityConstraints operator>(LHS&& lhs, RHS&& rhs) {
722 return lhs >= rhs;
723}
724
725/**
726 * Greater-than-or-equal-to comparison operator that returns an inequality
727 * constraint for two Variables.
728 *
729 * @param lhs Left-hand side.
730 * @param rhs Left-hand side.
731 */
732template <typename LHS, typename RHS>
733 requires(ScalarLike<LHS> || MatrixLike<LHS>) &&
734 (ScalarLike<RHS> || MatrixLike<RHS>) &&
735 (SleipnirType<LHS> || SleipnirType<RHS>)
736InequalityConstraints operator>=(LHS&& lhs, RHS&& rhs) {
737 return InequalityConstraints{lhs, rhs};
738}
739
740} // namespace slp
741
742namespace Eigen {
743
744/**
745 * NumTraits specialization that allows instantiating Eigen types with Variable.
746 */
747template <>
748struct NumTraits<slp::Variable> : NumTraits<double> {
749 /// Real type.
751 /// Non-integer type.
753 /// Nested type.
755
756 /// Is complex.
757 static constexpr int IsComplex = 0;
758 /// Is integer.
759 static constexpr int IsInteger = 0;
760 /// Is signed.
761 static constexpr int IsSigned = 1;
762 /// Require initialization.
763 static constexpr int RequireInitialization = 1;
764 /// Read cost.
765 static constexpr int ReadCost = 1;
766 /// Add cost.
767 static constexpr int AddCost = 3;
768 /// Multiply cost.
769 static constexpr int MulCost = 3;
770};
771
772} // namespace Eigen
#define slp_assert(condition)
Abort in C++.
Definition assert.hpp:27
sign
Definition base.h:682
This class calculates the Hessian of a variable with respect to a vector of variables.
Definition hessian.hpp:30
This class calculates the Jacobian of a vector of variables with respect to a vector of variables.
Definition jacobian.hpp:26
An autodiff variable pointing to an expression node.
Definition variable.hpp:40
Variable(detail::ExpressionPtr &&expr)
Constructs a Variable pointing to the specified expression.
Definition variable.hpp:80
friend SLEIPNIR_DLLEXPORT Variable operator+(const Variable &lhs)
Unary plus operator.
Definition variable.hpp:221
friend SLEIPNIR_DLLEXPORT Variable operator*(const Variable &lhs, const Variable &rhs)
Variable-Variable multiplication operator.
Definition variable.hpp:122
Variable & operator=(double value)
Assignment operator for double.
Definition variable.hpp:88
Variable(std::nullptr_t)
Constructs an empty Variable.
Definition variable.hpp:50
Variable & operator-=(const Variable &rhs)
Variable-Variable compound subtraction operator.
Definition variable.hpp:202
friend SLEIPNIR_DLLEXPORT Variable operator-(const Variable &lhs)
Unary minus operator.
Definition variable.hpp:212
friend SLEIPNIR_DLLEXPORT Variable operator+(const Variable &lhs, const Variable &rhs)
Variable-Variable addition operator.
Definition variable.hpp:168
Variable & operator+=(const Variable &rhs)
Variable-Variable compound addition operator.
Definition variable.hpp:179
friend SLEIPNIR_DLLEXPORT Variable operator-(const Variable &lhs, const Variable &rhs)
Variable-Variable subtraction operator.
Definition variable.hpp:191
Variable & operator*=(const Variable &rhs)
Variable-Variable compound multiplication operator.
Definition variable.hpp:133
Variable(std::floating_point auto value)
Constructs a Variable from a floating point type.
Definition variable.hpp:57
friend SLEIPNIR_DLLEXPORT Variable operator/(const Variable &lhs, const Variable &rhs)
Variable-Variable division operator.
Definition variable.hpp:145
Variable()=default
Constructs a linear Variable with a value of zero.
Variable(std::integral auto value)
Constructs a Variable from an integral type.
Definition variable.hpp:65
void set_value(double value)
Sets Variable's internal value.
Definition variable.hpp:100
Variable & operator/=(const Variable &rhs)
Variable-Variable compound division operator.
Definition variable.hpp:156
ExpressionType type() const
Returns the type of this expression (constant, linear, quadratic, or nonlinear).
Definition variable.hpp:246
double value()
Returns the value of this variable.
Definition variable.hpp:230
Variable(const detail::ExpressionPtr &expr)
Constructs a Variable pointing to the specified expression.
Definition variable.hpp:73
This class is an adaptor type that performs value updates of an expression's adjoint graph.
Definition adjoint_expression_graph.hpp:22
Definition concepts.hpp:40
Definition concepts.hpp:13
Definition concepts.hpp:37
Definition variable.hpp:742
Converts a string literal into a format string that will be parsed at compile time and converted into...
Definition printf.h:50
wpi::SmallVector< T > small_vector
Definition small_vector.hpp:10
ExpressionPtr log10(const ExpressionPtr &x)
std::log10() for Expressions.
Definition expression.hpp:1386
ExpressionPtr tanh(const ExpressionPtr &x)
std::tanh() for Expressions.
Definition expression.hpp:1794
gch::small_vector< Expression * > topological_sort(const ExpressionPtr &root)
Generate a topological sort of an expression graph from parent to child.
Definition expression_graph.hpp:20
ExpressionPtr sqrt(const ExpressionPtr &x)
std::sqrt() for Expressions.
Definition expression.hpp:1695
ExpressionPtr tan(const ExpressionPtr &x)
std::tan() for Expressions.
Definition expression.hpp:1745
ExpressionPtr pow(const ExpressionPtr &base, const ExpressionPtr &power)
std::pow() for Expressions.
Definition expression.hpp:1473
ExpressionPtr exp(const ExpressionPtr &x)
std::exp() for Expressions.
Definition expression.hpp:1224
ExpressionPtr hypot(const ExpressionPtr &x, const ExpressionPtr &y)
std::hypot() for Expressions.
Definition expression.hpp:1286
ExpressionPtr atan(const ExpressionPtr &x)
std::atan() for Expressions.
Definition expression.hpp:964
ExpressionPtr erf(const ExpressionPtr &x)
std::erf() for Expressions.
Definition expression.hpp:1175
ExpressionPtr sinh(const ExpressionPtr &x)
std::sinh() for Expressions.
Definition expression.hpp:1645
ExpressionPtr acos(const ExpressionPtr &x)
std::acos() for Expressions.
Definition expression.hpp:866
ExpressionPtr cosh(const ExpressionPtr &x)
std::cosh() for Expressions.
Definition expression.hpp:1124
void update_values(const gch::small_vector< Expression * > &list)
Update the values of all nodes in this graph based on the values of their dependent nodes.
Definition expression_graph.hpp:77
ExpressionPtr atan2(const ExpressionPtr &y, const ExpressionPtr &x)
std::atan2() for Expressions.
Definition expression.hpp:1025
ExpressionPtr cos(const ExpressionPtr &x)
std::cos() for Expressions.
Definition expression.hpp:1076
static ExpressionPtr make_expression_ptr(Args &&... args)
Creates an intrusive shared pointer to an expression from the global pool allocator.
Definition expression.hpp:48
ExpressionPtr cbrt(const ExpressionPtr &x)
std::cbrt() for Expressions.
Definition expression.hpp:547
ExpressionPtr log(const ExpressionPtr &x)
std::log() for Expressions.
Definition expression.hpp:1336
ExpressionPtr sin(const ExpressionPtr &x)
std::sin() for Expressions.
Definition expression.hpp:1596
ExpressionPtr abs(const ExpressionPtr &x)
std::abs() for Expressions.
Definition expression.hpp:816
ExpressionPtr asin(const ExpressionPtr &x)
std::asin() for Expressions.
Definition expression.hpp:915
Definition expression_graph.hpp:11
SLEIPNIR_DLLEXPORT Variable sinh(const Variable &x)
std::sinh() for Variables.
Definition variable.hpp:446
ExpressionType
Expression type.
Definition expression_type.hpp:18
gch::small_vector< Variable > make_constraints(LHS &&lhs, RHS &&rhs)
Make a list of constraints.
Definition variable.hpp:504
SLEIPNIR_DLLEXPORT Variable log10(const Variable &x)
std::log10() for Variables.
Definition variable.hpp:419
SLEIPNIR_DLLEXPORT Variable cos(const Variable &x)
std::cos() for Variables.
Definition variable.hpp:353
SLEIPNIR_DLLEXPORT Variable erf(const Variable &x)
std::erf() for Variables.
Definition variable.hpp:371
SLEIPNIR_DLLEXPORT Variable cbrt(const Variable &x)
std::cbrt() for Variables.
Definition variable.hpp:344
SLEIPNIR_DLLEXPORT Variable acos(const Variable &x)
std::acos() for Variables.
Definition variable.hpp:307
SLEIPNIR_DLLEXPORT Variable pow(const Variable &base, const Variable &power)
std::pow() for Variables.
Definition variable.hpp:400
SLEIPNIR_DLLEXPORT Variable log(const Variable &x)
std::log() for Variables.
Definition variable.hpp:410
SLEIPNIR_DLLEXPORT Variable sqrt(const Variable &x)
std::sqrt() for Variables.
Definition variable.hpp:455
SLEIPNIR_DLLEXPORT Variable atan(const Variable &x)
std::atan() for Variables.
Definition variable.hpp:325
SLEIPNIR_DLLEXPORT Variable abs(const Variable &x)
std::abs() for Variables.
Definition variable.hpp:298
void println(fmt::format_string< T... > fmt, T &&... args)
Wrapper around fmt::println() that squelches write failure exceptions.
Definition print.hpp:48
SLEIPNIR_DLLEXPORT Variable tanh(const Variable &x)
std::tanh() for Variables.
Definition variable.hpp:473
SLEIPNIR_DLLEXPORT Variable hypot(const Variable &x, const Variable &y)
std::hypot() for Variables.
Definition variable.hpp:390
SLEIPNIR_DLLEXPORT Variable atan2(const Variable &y, const Variable &x)
std::atan2() for Variables.
Definition variable.hpp:335
SLEIPNIR_DLLEXPORT Variable sin(const Variable &x)
std::sin() for Variables.
Definition variable.hpp:437
SLEIPNIR_DLLEXPORT Variable asin(const Variable &x)
std::asin() for Variables.
Definition variable.hpp:316
SLEIPNIR_DLLEXPORT Variable cosh(const Variable &x)
std::cosh() for Variables.
Definition variable.hpp:362
Definition PointerIntPair.h:280
A vector of equality constraints of the form cₑ(x) = 0.
Definition variable.hpp:545
gch::small_vector< Variable > constraints
A vector of scalar equality constraints.
Definition variable.hpp:547
EqualityConstraints(std::initializer_list< EqualityConstraints > equality_constraints)
Concatenates multiple equality constraints.
Definition variable.hpp:554
EqualityConstraints(const std::vector< EqualityConstraints > &equality_constraints)
Concatenates multiple equality constraints.
Definition variable.hpp:569
EqualityConstraints(LHS &&lhs, RHS &&rhs)
Constructs an equality constraint from a left and right side.
Definition variable.hpp:590
A vector of inequality constraints of the form cᵢ(x) ≥ 0.
Definition variable.hpp:606
InequalityConstraints(const std::vector< InequalityConstraints > &inequality_constraints)
Concatenates multiple inequality constraints.
Definition variable.hpp:632
InequalityConstraints(std::initializer_list< InequalityConstraints > inequality_constraints)
Concatenates multiple inequality constraints.
Definition variable.hpp:616
InequalityConstraints(LHS &&lhs, RHS &&rhs)
Constructs an inequality constraint from a left and right side.
Definition variable.hpp:653
gch::small_vector< Variable > constraints
A vector of scalar inequality constraints.
Definition variable.hpp:608
#define SLEIPNIR_DLLEXPORT
Definition symbol_exports.hpp:34