version 0.4.1
autodiffhelper.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2021-2024 The Ikarus Developers mueller@ibb.uni-stuttgart.de
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
9#pragma once
10#include <autodiff/forward/dual.hpp>
11#include <autodiff/forward/dual/eigen.hpp>
12
13namespace Ikarus::utils {
14
34template <typename Fun, typename... Vars, typename... Args, typename U, typename G, typename H>
35void hessianN(const Fun& f, const autodiff::Wrt<Vars...>& wrt, const autodiff::At<Args...>& at, U& u,
36 std::array<G, U::RowsAtCompileTime>& g, std::array<H, U::RowsAtCompileTime>& h) {
37 static_assert(sizeof...(Vars) >= 1);
38 static_assert(sizeof...(Args) >= 1);
39
40 auto fEntry = [&](auto& I) { return [&](const auto&) { return std::apply(f, at.args)[I]; }; };
41 for (int i = 0; i < U::RowsAtCompileTime; ++i)
42 hessian(fEntry(i), wrt, at, u[i], g[i], h[i]);
43}
44} // namespace Ikarus::utils
void hessianN(const Fun &f, const autodiff::Wrt< Vars... > &wrt, const autodiff::At< Args... > &at, U &u, std::array< G, U::RowsAtCompileTime > &g, std::array< H, U::RowsAtCompileTime > &h)
Computes the Hessian matrix for each parameter of a given function.The Hessian matrix represents the ...
Definition: autodiffhelper.hh:35
Definition: algorithms.hh:17