6#ifndef THEORETICA_AUTODIFF_H
7#define THEORETICA_AUTODIFF_H
12#include "../algebra/vec.h"
13#include "../algebra/mat.h"
14#include "../core/error.h"
15#include "../core/core_traits.h"
42 return f(
dual(x, 1.0)).Dual();
115 constexpr size_t N = MultidualType::vector_argument;
121 for (
unsigned int i = 0; i < x.size(); ++i) {
201 MultidualT d = f(MultidualT::make_argument(x));
204 for (
unsigned int i = 0; i < d.v.size(); ++i)
242 template<
unsigned int N = 0,
unsigned int M = 0>
252 for (
unsigned int j = 0;
j <
J.rows(); ++
j)
253 for (
unsigned int i = 0; i <
res[
j].v.size(); ++i)
267 template<
unsigned int N = 0,
unsigned int M = 0>
285 template<
unsigned int N = 0>
300 res[0] =
J(2, 1) -
J(1, 2);
301 res[1] =
J(0, 2) -
J(2, 0);
302 res[2] =
J(1, 0) -
J(0, 1);
316 template<
unsigned int N = 0>
340 template<
unsigned int N = 0>
364 template<
unsigned int N = 0>
382 template<
unsigned int N = 0>
389 for (
unsigned int i = 0; i < x.
size(); ++i)
392 for (
unsigned int i = 0; i < x.
size(); ++i) {
410 template<
unsigned int N = 0>
433 template<
unsigned int N = 0>
Types and traits for automatic differentiation.
Second order dual number class.
Definition dual2.h:29
real Dual2() const
Return second order dual part.
Definition dual2.h:95
Dual number class.
Definition dual.h:28
A generic matrix with a fixed number of rows and columns.
Definition mat.h:136
Multidual number algebra for functions of the form .
Definition multidual.h:26
A statically allocated N-dimensional vector with elements of the given type.
Definition vec.h:92
void resize(size_t n) const
Compatibility function to allow for allocation or resizing of dynamic vectors.
Definition vec.h:416
TH_CONSTEXPR unsigned int size() const
Returns the size of the vector (N)
Definition vec.h:406
Second order dual number class.
#define TH_MATH_ERROR(F_NAME, VALUE, EXCEPTION)
TH_MATH_ERROR is a macro which throws exceptions or modifies errno (depending on which compiling opti...
Definition error.h:219
vec< real, N > curl(vec< multidual< N >, N >(*f)(vec< multidual< N >, N >), const vec< real, N > &x)
Compute the curl for a given of a vector field defined by using automatic differentiation.
Definition autodiff.h:286
real sturm_liouville(multidual< N >(*f)(vec< multidual< N >, N >), multidual< N >(*H)(vec< multidual< N >, N >), vec< real, N > eta)
Compute the Sturm-Liouville operator on a generic function of the form with respect to a given Hamil...
Definition autodiff.h:434
real deriv(DualFunction f, real x)
Compute the derivative of a function at the given point using univariate automatic differentiation.
Definition autodiff.h:41
vec< real, N > directional_derivative(multidual< N >(*f)(vec< multidual< N >, N >), const vec< real, N > &x, const vec< real, N > &v)
Compute the directional derivative of a generic function of the form .
Definition autodiff.h:341
real laplacian(dual2(*f)(vec< dual2, N >), const vec< real, N > &x)
Compute the Laplacian differential operator for a generic function of the form at a given $\vec x$.
Definition autodiff.h:383
real deriv2(Dual2Function f, real x)
Compute the second derivative of a function at the given point using univariate automatic differentia...
Definition autodiff.h:77
auto gradient(Function f, const Vector &x)
Compute the gradient for a given of a scalar field of the form using automatic differentiation.
Definition autodiff.h:148
auto make_autodiff_arg(const Vector &x)
Prepare a vector of multidual numbers in "canonical" form, where the i-th element of the vector has a...
Definition autodiff.h:113
mat< real, M, N > jacobian(vec< multidual< N >, M >(*f)(vec< multidual< N >, N >), const vec< real, N > &x)
Compute the jacobian of a vector field of the form .
Definition autodiff.h:243
real divergence(Function f, const Vector &x)
Compute the divergence for a given of a scalar field of the form using automatic differentiation.
Definition autodiff.h:198
Main namespace of the library which contains all functions and objects.
Definition algebra.h:27
double real
A real number, defined as a floating point type.
Definition constants.h:198
typename _internal::func_helper< Function >::return_type return_type_t
Extract the return type of a Callable object, such as a function pointer or lambda function.
Definition core_traits.h:255
std::remove_reference_t< decltype(std::declval< Structure >()[0])> vector_element_t
Extract the type of a vector (or any indexable container) from its operator[].
Definition core_traits.h:134
real nan()
Return a quiet NaN number in floating point representation.
Definition error.h:54