Skip to content

Commit

Permalink
Include gradient tree generation in Hessian setup time (SleipnirGroup…
Browse files Browse the repository at this point in the history
  • Loading branch information
calcmogul authored Jan 17, 2025
1 parent ecdb394 commit 9537d65
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
16 changes: 13 additions & 3 deletions include/sleipnir/autodiff/Hessian.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class SLEIPNIR_DLLEXPORT Hessian {
Hessian(Variable variable, const VariableMatrix& wrt) noexcept
: m_jacobian{
[&] {
m_profiler.StartSetup();

small_vector<detail::ExpressionPtr> wrtVec;
wrtVec.reserve(wrt.size());
for (auto& elem : wrt) {
Expand All @@ -52,7 +54,9 @@ class SLEIPNIR_DLLEXPORT Hessian {
}
return ret;
}(),
wrt} {}
wrt} {
m_profiler.StopSetup();
}

/**
* Returns the Hessian as a VariableMatrix.
Expand All @@ -65,14 +69,20 @@ class SLEIPNIR_DLLEXPORT Hessian {
/**
* Evaluates the Hessian at wrt's value.
*/
const Eigen::SparseMatrix<double>& Value() { return m_jacobian.Value(); }
const Eigen::SparseMatrix<double>& Value() {
m_profiler.StartSolve();
const auto& H = m_jacobian.Value();
m_profiler.StopSolve();
return H;
}

/**
* Returns the profiler.
*/
Profiler& GetProfiler() { return m_jacobian.GetProfiler(); }
Profiler& GetProfiler() { return m_profiler; }

private:
Profiler m_profiler;
Jacobian m_jacobian;
};

Expand Down
5 changes: 3 additions & 2 deletions include/sleipnir/autodiff/Jacobian.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,13 @@ class SLEIPNIR_DLLEXPORT Jacobian {
* Evaluates the Jacobian at wrt's value.
*/
const Eigen::SparseMatrix<double>& Value() {
m_profiler.StartSolve();

if (m_nonlinearRows.empty()) {
m_profiler.StopSolve();
return m_J;
}

m_profiler.StartSolve();

for (auto& graph : m_graphs) {
graph.Update();
}
Expand Down
2 changes: 2 additions & 0 deletions jormungandr/cpp/Docstrings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ static const char *__doc_sleipnir_Hessian_Value = R"doc(Evaluates the Hessian at

static const char *__doc_sleipnir_Hessian_m_jacobian = R"doc()doc";

static const char *__doc_sleipnir_Hessian_m_profiler = R"doc()doc";

static const char *__doc_sleipnir_InequalityConstraints = R"doc(A vector of inequality constraints of the form cᵢ(x) ≥ 0.)doc";

static const char *__doc_sleipnir_InequalityConstraints_InequalityConstraints =
Expand Down

0 comments on commit 9537d65

Please sign in to comment.