37#ifndef VIGRA_AUTODIFF_HXX
38#define VIGRA_AUTODIFF_HXX
40#include "tinyvector.hxx"
41#include "mathutil.hxx"
86template <
class T,
int N>
139 d[targetElement] = T(1.0);
194 d = o.v * d + v * o.d;
208 d = (o.v * d - v * o.d) / sq(o.v);
224template <
class T,
int N>
225TinyVector<DualVector<T, N>, N>
226dualMatrix(TinyVector<T, N>
const & v)
228 TinyVector<DualVector<T, N>, N> res;
229 for(
int k=0; k<N; ++k)
232 res[k].d[k] = T(1.0);
237template <
class T,
int N>
243template <
class T,
int N>
249template <
class T,
int N>
255template <
class T,
int N>
261template <
class T,
int N>
267template <
class T,
int N>
273template <
class T,
int N>
279template <
class T,
int N>
285template <
class T,
int N>
291template <
class T,
int N>
297template <
class T,
int N>
303template <
class T,
int N>
311template <
typename T,
int N>
314 return v.v < T(0.0) ? -v : v;
319template <
typename T,
int N>
322 return v.v < T(0.0) ? -v : v;
327template <
typename T,
int N>
337template <
class T,
int N>
347template <
typename T,
int N>
358template <
typename T,
int N>
367template <
typename T,
int N>
378template <
typename T,
int N>
381 v.d *= M_PI*cos_pi(v.v);
387template <
typename T,
int N>
390 v.d *= -M_PI*sin_pi(v.v);
397template <
typename T,
int N>
400 v.d /= sqrt(T(1.0) - sq(v.v));
407template <
typename T,
int N>
410 v.d /= -sqrt(T(1.0) - sq(v.v));
417template <
typename T,
int N>
421 v.d *= T(1.0) + sq(v.v);
427template <
typename T,
int N>
430 v.d /= T(1.0) + sq(v.v);
438template <
typename T,
int N>
447template <
typename T,
int N>
457template <
typename T,
int N>
461 v.d *= T(1.0) - sq(v.v);
467template <
class T,
int N>
477template <
typename T,
int N>
480 v1.d = (v2.v * v1.d - v1.v * v2.d) / (sq(v1.v) + sq(v2.v));
481 v1.v = atan2(v1.v, v2.v);
488template <
typename T,
int N>
491 T pow_p_1 = pow(v.v, p-T(1.0));
498template <
typename T,
int N>
508template <
typename T,
int N>
511 T pow_p_1 = pow(v.v, p.v-T(1.0)),
512 pow_p = v.v * pow_p_1;
513 v.d = p.v * pow_p_1 * v.d + pow_p * log(v.v) * p.d;
519template <
class T,
int N>
527template <
class T,
int N>
535template <
class T,
int N>
544template <
class T,
int N>
552template <
class T,
int N>
560template <
class T,
int N>
568template <
class T,
int N>
572 return v1.v == v2.v && v1.d == v2.d;
575template <
class T,
int N>
579 return v1.v != v2.v || v1.d != v2.d;
582#define VIGRA_DUALVECTOR_RELATIONAL_OPERATORS(op) \
583template <class T, int N> \
585operator op(DualVector<T, N> const & v1, DualVector<T, N> const & v2) \
587 return v1.v op v2.v; \
590template <class T, int N> \
592operator op(T v1, DualVector<T, N> const & v2) \
597template <class T, int N> \
599operator op(DualVector<T, N> const & v1, T v2) \
604VIGRA_DUALVECTOR_RELATIONAL_OPERATORS(<)
605VIGRA_DUALVECTOR_RELATIONAL_OPERATORS(<=)
606VIGRA_DUALVECTOR_RELATIONAL_OPERATORS(>)
607VIGRA_DUALVECTOR_RELATIONAL_OPERATORS(>=)
609#undef VIGRA_DUALVECTOR_RELATIONAL_OPERATORS
611template <
class T,
int N>
614 T epsilon = NumericTraits<T>::epsilon())
626template <
class T,
int N>
628operator<<(ostream & out, vigra::autodiff::DualVector<T, N>
const & l)
630 out << l.v <<
" " << l.d;
Class for fixed size vectors.
Definition tinyvector.hxx:1008
Definition autodiff.hxx:88
DualVector(T const &val, T const &g0, T const &g1)
Definition autodiff.hxx:126
T value_type
type of function values and gradient elements
Definition autodiff.hxx:90
DualVector(T const &val, int targetElement)
Definition autodiff.hxx:136
Gradient const & gradient() const
Definition autodiff.hxx:151
DualVector(T const &val)
Definition autodiff.hxx:104
DualVector(T const &val, T const &g0)
Definition autodiff.hxx:118
TinyVector< T, N > Gradient
type of the gradient vector
Definition autodiff.hxx:91
DualVector(T const &val, Gradient const &grad)
Definition autodiff.hxx:110
DualVector()
Definition autodiff.hxx:98
T value() const
Definition autodiff.hxx:144
REAL cos_pi(REAL x)
cos(pi*x).
Definition mathutil.hxx:1242
REAL sin_pi(REAL x)
sin(pi*x).
Definition mathutil.hxx:1204
SquareRootTraits< FixedPoint< IntBits, FracBits > >::SquareRootResult sqrt(FixedPoint< IntBits, FracBits > v)
square root.
Definition fixedpoint.hxx:616
NumericTraits< T >::Promote sq(T t)
The square function.
Definition mathutil.hxx:382
FFTWComplex< R >::NormType abs(const FFTWComplex< R > &a)
absolute value (= magnitude)
Definition fftw3.hxx:1002
bool closeAtTolerance(T1 l, T2 r, typename PromoteTraits< T1, T2 >::Promote epsilon)
Tolerance based floating-point equality.
Definition mathutil.hxx:1638
Diff2D operator-(Diff2D const &a, Diff2D const &b)
Definition diff2d.hxx:697