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();
120 enable_vector<Vector> =
true
127 constexpr size_t N = MultidualType::size_argument;
133 for (
unsigned int i = 0; i < x.size(); ++i) {
139 return f(arg).Dual();
160 constexpr size_t N = return_type_t<Function>::size_argument;
182 enable_vector<Vector> =
true
187 const size_t N = MultidualT::size_argument;
193 for (
unsigned int i = 0; i <
res.size(); ++i) {
197 if (
res[i].v.size() > i)
221 constexpr size_t N = return_type_t<Function>::size_argument;
239 enable_vector<Vector> =
true,
244 constexpr size_t M = return_type_t<MultidualFunction>::size_argument;
245 constexpr size_t N = _internal::func_helper<MultidualFunction>::first_arg_type::size_argument;
253 for (
unsigned int j = 0;
j <
J.rows(); ++
j) {
266 for (; i <
J.cols(); ++i)
287 constexpr size_t N = return_type_t<MultidualFunction>::size_argument;
290 return [f](
const Vector& x) {
306 enable_vector<Vector> =
true,
319 constexpr size_t N = return_type_t<MultidualFunction>::size_argument;
322 res[0] =
J(2, 1) -
J(1, 2);
323 res[1] =
J(0, 2) -
J(2, 0);
324 res[2] =
J(1, 0) -
J(0, 1);
344 constexpr size_t N = return_type_t<MultidualFunction>::size_argument;
347 return [f](
const Vector& x) {
363 enable_vector<Vector> =
true
368 constexpr size_t N = _internal::func_helper<Dual2Function>
369 ::first_arg_type::size_argument;
374 for (
unsigned int i = 0; i < d.
size(); ++i)
379 for (
unsigned int i = 0; i < d.
size(); ++i) {
397 template <
typename Dual2Function>
400 constexpr size_t N = _internal::func_helper<Dual2Function>
401 ::first_arg_type::size_argument;
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
mat< Type, N, K > resize(unsigned int n, unsigned int k)
Compatibility function to allow for allocation or resizing of dynamic matrices.
Definition mat.h:730
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:459
TH_CONSTEXPR unsigned int size() const
Returns the size of the vector (N)
Definition vec.h:449
#define TH_MATH_ERROR(F_NAME, VALUE, EXCEPTION)
TH_MATH_ERROR is a macro which throws exceptions or modifies errno (depending on which compilation op...
Definition error.h:219
Second order dual number class.
Matrix & mat_error(Matrix &m)
Overwrite the given matrix with the error matrix with NaN values on the diagonal and zeroes everywher...
Definition algebra.h:40
Vector & vec_error(Vector &v)
Overwrite the given vector with the error vector with NaN values.
Definition algebra.h:58
real laplacian(Dual2Function f, const Vector &x)
Compute the Laplacian differential operator for a generic function of the form at a given $\vec x$.
Definition autodiff.h:365
auto jacobian(MultidualFunction f, const Vector &x)
Compute the jacobian of a vector field of the form .
Definition autodiff.h:242
real deriv(DualFunction f, real x)
Compute the derivative of a function at the given point using univariate automatic differentiation.
Definition autodiff.h:41
auto curl(MultidualFunction f, const Vector &x)
Compute the curl for a given of a vector field defined by using automatic differentiation.
Definition autodiff.h:309
real divergence(Function V, const Vector &x)
Compute the divergence for a given of a vector field of the form using automatic differentiation.
Definition autodiff.h:184
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:122
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:207
Vector make_error()
Create a vector representing an error state, with all NaN values.
Definition algebra.h:103
@ InvalidArgument
Invalid argument.