35 : m_variables{std::move(variables)}, m_wrt{std::move(wrt)} {
36 m_profiler.StartSetup();
38 for (
int row = 0; row < m_wrt.Rows(); ++row) {
39 m_wrt(row).expr->row = row;
42 for (
auto& variable : m_variables) {
43 m_graphs.emplace_back(variable);
46 for (
int row = 0; row < m_variables.Rows(); ++row) {
47 if (m_variables(row).Type() == ExpressionType::kLinear) {
51 m_graphs[row].ComputeAdjoints([&](
int col,
double adjoint) {
52 m_cachedTriplets.emplace_back(row, col, adjoint);
54 }
else if (m_variables(row).Type() > ExpressionType::kLinear) {
57 m_nonlinearRows.emplace_back(row);
61 for (
int row = 0; row < m_wrt.Rows(); ++row) {
62 m_wrt(row).expr->row = -1;
65 if (m_nonlinearRows.empty()) {
66 m_J.setFromTriplets(m_cachedTriplets.begin(), m_cachedTriplets.end());
69 m_profiler.StopSetup();
100 const Eigen::SparseMatrix<double>&
Value() {
101 m_profiler.StartSolve();
103 if (m_nonlinearRows.empty()) {
104 m_profiler.StopSolve();
108 for (
auto& graph : m_graphs) {
114 auto triplets = m_cachedTriplets;
117 for (
int row : m_nonlinearRows) {
118 m_graphs[row].ComputeAdjoints([&](
int col,
double adjoint) {
119 triplets.emplace_back(row, col, adjoint);
123 m_J.setFromTriplets(triplets.begin(), triplets.end());
125 m_profiler.StopSolve();