Optimist  0.0.0
A C++ library for optimization
Loading...
Searching...
No Matches
VectorFunction.hh
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
2 * Copyright (c) 2025, Davide Stocco, Mattia Piazza and Enrico Bertolazzi. *
3 * *
4 * The Optimist project is distributed under the BSD 2-Clause License. *
5 * *
6 * Davide Stocco Mattia Piazza Enrico Bertolazzi *
7 * University of Trento University of Trento University of Trento *
8 * davide.stocco@unitn.it mattia.piazza@unitn.it enrico.bertolazzi@unitn.it *
9\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
10
11#pragma once
12
13#ifndef OPTIMIST_VECTOR_FUNCTION_HH
14#define OPTIMIST_VECTOR_FUNCTION_HH
15
16#include "Optimist/Function.hh"
17
18namespace Optimist
19{
20
30 template <typename Real, Integer N, Integer M, typename DerivedFunction>
31 class VectorFunction : public Function<Real, N, M, DerivedFunction>
32 {
33 public:
35
36 // Fancy static assertions (just for fun, don't take it too seriously)
37 static_assert(N != static_cast<Integer>(0) && M != static_cast<Integer>(0),
38 "Are you sure you want to a zero-dimensional system of equations?");
39 static_assert(N != static_cast<Integer>(1) && M != static_cast<Integer>(1),
40 "C'mon, let's not kid ourselves. Use a scalar function...");
41 static_assert(M != static_cast<Integer>(1),
42 "Good try, but you're looking for an objective function, not a vector-valued function.");
43
44 // I/O types
47
48 // Derivative types
51
56
61 std::string name() const {return static_cast<const DerivedFunction *>(this)->name_impl();}
62
68 void evaluate(const InputVector & x, OutputVector & out) const
69 {
70 static_cast<const DerivedFunction *>(this)->evaluate_impl(x, out);
71 }
72
78 void jacobian(const InputVector & x, Matrix & out) const
79 {
80 static_cast<const DerivedFunction *>(this)->first_derivative_impl(x, out);
81 }
82
88 void hessian(const InputVector & x, Tensor & out) const
89 {
90 static_cast<const DerivedFunction *>(this)->second_derivative_impl(x, out);
91 }
92
93 }; // class VectorFunction
94
95} // namespace Optimist
96
97#endif // OPTIMIST_VECTOR_FUNCTION_HH
std::conditional_t< FunInDim==1 &&FunOutDim==1, Real, std::conditional_t< FunInDim==1||FunOutDim==1, Eigen::Matrix< Real, FunInDim, FunInDim >, std::vector< Eigen::Matrix< Real, FunInDim, FunInDim > > > > SecondDerivativeType
Definition Function.hh:47
typename std::conditional_t< FunInDim==1, Real, Eigen::Vector< Real, FunInDim > > InputType
Definition Function.hh:42
std::conditional_t< FunInDim==1 &&FunOutDim==1, Real, Eigen::Matrix< Real, FunOutDim, FunInDim > > FirstDerivativeType
Definition Function.hh:46
typename std::conditional_t< FunOutDim==1, Real, Eigen::Vector< Real, FunOutDim > > OutputType
Definition Function.hh:43
typename Function< Real, N, M, DerivedFunction >::SecondDerivativeType Tensor
Definition VectorFunction.hh:50
VectorFunction()
Definition VectorFunction.hh:55
void jacobian(const InputVector &x, Matrix &out) const
Definition VectorFunction.hh:78
void evaluate(const InputVector &x, OutputVector &out) const
Definition VectorFunction.hh:68
typename Function< Real, N, M, DerivedFunction >::InputType InputVector
Definition VectorFunction.hh:45
typename Function< Real, N, M, DerivedFunction >::FirstDerivativeType Matrix
Definition VectorFunction.hh:49
typename Function< Real, N, M, DerivedFunction >::OutputType OutputVector
Definition VectorFunction.hh:46
std::string name() const
Definition VectorFunction.hh:61
void hessian(const InputVector &x, Tensor &out) const
Definition VectorFunction.hh:88
Namespace for the Optimist library.
Definition Optimist.hh:87
OPTIMIST_DEFAULT_INTEGER_TYPE Integer
The Integer type as used for the API.
Definition Optimist.hh:95