37 #ifndef VIGRA_AUTODIFF_HXX 38 #define VIGRA_AUTODIFF_HXX 40 #include "tinyvector.hxx" 41 #include "mathutil.hxx" 86 template <
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);
224 template <
class T,
int N>
228 TinyVector<DualVector<T, N>, N> res;
229 for(
int k=0; k<N; ++k)
232 res[k].d[k] = T(1.0);
237 template <
class T,
int N>
243 template <
class T,
int N>
249 template <
class T,
int N>
255 template <
class T,
int N>
261 template <
class T,
int N>
267 template <
class T,
int N>
273 template <
class T,
int N>
279 template <
class T,
int N>
285 template <
class T,
int N>
291 template <
class T,
int N>
297 template <
class T,
int N>
303 template <
class T,
int N>
311 template <
typename T,
int N>
314 return v.v < T(0.0) ? -v : v;
319 template <
typename T,
int N>
322 return v.v < T(0.0) ? -v : v;
327 template <
typename T,
int N>
337 template <
class T,
int N>
347 template <
typename T,
int N>
358 template <
typename T,
int N>
367 template <
typename T,
int N>
378 template <
typename T,
int N>
387 template <
typename T,
int N>
397 template <
typename T,
int N>
400 v.d /=
sqrt(T(1.0) -
sq(v.v));
407 template <
typename T,
int N>
410 v.d /= -
sqrt(T(1.0) -
sq(v.v));
417 template <
typename T,
int N>
421 v.d *= T(1.0) +
sq(v.v);
427 template <
typename T,
int N>
430 v.d /= T(1.0) +
sq(v.v);
438 template <
typename T,
int N>
447 template <
typename T,
int N>
457 template <
typename T,
int N>
461 v.d *= T(1.0) -
sq(v.v);
467 template <
class T,
int N>
477 template <
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);
488 template <
typename T,
int N>
491 T pow_p_1 = pow(v.v, p-T(1.0));
498 template <
typename T,
int N>
508 template <
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;
519 template <
class T,
int N>
527 template <
class T,
int N>
535 template <
class T,
int N>
544 template <
class T,
int N>
552 template <
class T,
int N>
560 template <
class T,
int N>
568 template <
class T,
int N>
572 return v1.v == v2.v && v1.d == v2.d;
575 template <
class T,
int N>
579 return v1.v != v2.v || v1.d != v2.d;
582 #define VIGRA_DUALVECTOR_RELATIONAL_OPERATORS(op) \ 583 template <class T, int N> \ 585 operator op(DualVector<T, N> const & v1, DualVector<T, N> const & v2) \ 587 return v1.v op v2.v; \ 590 template <class T, int N> \ 592 operator op(T v1, DualVector<T, N> const & v2) \ 597 template <class T, int N> \ 599 operator op(DualVector<T, N> const & v1, T v2) \ 604 VIGRA_DUALVECTOR_RELATIONAL_OPERATORS(<)
605 VIGRA_DUALVECTOR_RELATIONAL_OPERATORS(<=)
606 VIGRA_DUALVECTOR_RELATIONAL_OPERATORS(>)
607 VIGRA_DUALVECTOR_RELATIONAL_OPERATORS(>=)
609 #undef VIGRA_DUALVECTOR_RELATIONAL_OPERATORS 611 template <
class T,
int N>
614 T epsilon = NumericTraits<T>::epsilon())
626 template <
class T,
int N>
628 operator<<(ostream & out, vigra::autodiff::DualVector<T, N>
const & l)
630 out << l.v <<
" " << l.d;
636 #endif // VIGRA_AUTODIFF_HXX REAL sin_pi(REAL x)
sin(pi*x).
Definition: mathutil.hxx:1166
TinyVector< T, N > Gradient
type of the gradient vector
Definition: autodiff.hxx:91
linalg::TemporaryMatrix< T > acos(MultiArrayView< 2, T, C > const &v)
FixedPoint16< 2, OverflowHandling > atan2(FixedPoint16< IntBits, OverflowHandling > y, FixedPoint16< IntBits, OverflowHandling > x)
Arctangent. Accuracy better than 1/3 degree (9 significant bits).
Definition: fixedpoint.hxx:1654
linalg::TemporaryMatrix< T > sin(MultiArrayView< 2, T, C > const &v)
Definition: autodiff.hxx:87
linalg::TemporaryMatrix< T > exp(MultiArrayView< 2, T, C > const &v)
Gradient const & gradient() const
Definition: autodiff.hxx:151
Definition: array_vector.hxx:903
T value() const
Definition: autodiff.hxx:144
linalg::TemporaryMatrix< T > asin(MultiArrayView< 2, T, C > const &v)
DualVector(T const &val)
Definition: autodiff.hxx:104
Definition: accessor.hxx:43
REAL cos_pi(REAL x)
cos(pi*x).
Definition: mathutil.hxx:1204
DualVector(T const &val, T const &g0)
Definition: autodiff.hxx:118
NumericTraits< T >::Promote sq(T t)
The square function.
Definition: mathutil.hxx:344
DualVector(T const &val, T const &g0, T const &g1)
Definition: autodiff.hxx:126
bool operator!=(FFTWComplex< R > const &a, const FFTWComplex< R > &b)
not equal
Definition: fftw3.hxx:841
T value_type
type of function values and gradient elements
Definition: autodiff.hxx:90
bool operator==(FFTWComplex< R > const &a, const FFTWComplex< R > &b)
equal
Definition: fftw3.hxx:825
DualVector(T const &val, Gradient const &grad)
Definition: autodiff.hxx:110
TinyVector< V, SIZE > pow(TinyVectorBase< V, SIZE, D1, D2 > const &v, E exponent)
Definition: tinyvector.hxx:1834
V const & max(TinyVectorBase< V, SIZE, D1, D2 > const &l)
maximum element
Definition: tinyvector.hxx:2008
DualVector()
Definition: autodiff.hxx:98
bool closeAtTolerance(T1 l, T2 r, typename PromoteTraits< T1, T2 >::Promote epsilon)
Tolerance based floating-point comparison.
Definition: mathutil.hxx:1600
linalg::TemporaryMatrix< T > log(MultiArrayView< 2, T, C > const &v)
FFTWComplex< R >::NormType abs(const FFTWComplex< R > &a)
absolute value (= magnitude)
Definition: fftw3.hxx:1002
linalg::TemporaryMatrix< T > atan(MultiArrayView< 2, T, C > const &v)
linalg::TemporaryMatrix< T > tan(MultiArrayView< 2, T, C > const &v)
linalg::TemporaryMatrix< T > cos(MultiArrayView< 2, T, C > const &v)
DualVector(T const &val, int targetElement)
Definition: autodiff.hxx:136
SquareRootTraits< FixedPoint< IntBits, FracBits > >::SquareRootResult sqrt(FixedPoint< IntBits, FracBits > v)
square root.
Definition: fixedpoint.hxx:616
V const & min(TinyVectorBase< V, SIZE, D1, D2 > const &l)
minimum element
Definition: tinyvector.hxx:1959