Skip to content

Commit

Permalink
add operator<<(std::ostream, Dual)
Browse files Browse the repository at this point in the history
  • Loading branch information
chriselrod committed Feb 16, 2024
1 parent faa6dab commit 4c7c27a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions include/Math/Dual.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <Math/StaticArrays.hpp>
#include <Utilities/Invariant.hpp>
#include <cstddef>
#include <istream>
#include <utility>

namespace poly::math {
Expand Down Expand Up @@ -824,6 +825,14 @@ constexpr auto dval(Dual<T, N> &x) -> double & {
return dval(x.value());
}

template <typename T, ptrdiff_t N>
auto operator<<(std::ostream &os, const Dual<T, N> &x) -> std::ostream & {
os << "Dual<" << N << ">{" << x.value();
for (ptrdiff_t n = 0; n < N; ++n) os << ", " << x.gradient()[n];
os << "}";
return os;
};

class GradientResult {
double x;
MutPtrVector<double> grad;
Expand Down

0 comments on commit 4c7c27a

Please sign in to comment.