forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gradient.h
36 lines (30 loc) · 981 Bytes
/
gradient.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/// @file
/// Utilities for arithmetic on gradients.
#pragma once
#include <Eigen/Dense>
namespace drake {
namespace math {
/*
* Recursively defined template specifying a matrix type of the correct size for
* a gradient of a matrix function with respect to Nq variables, of any order.
*/
template <typename Derived, int Nq, int DerivativeOrder = 1>
struct Gradient {
typedef typename Eigen::Matrix<
typename Derived::Scalar,
((Derived::SizeAtCompileTime == Eigen::Dynamic || Nq == Eigen::Dynamic)
? Eigen::Dynamic
: Gradient<Derived, Nq,
DerivativeOrder - 1>::type::SizeAtCompileTime),
Nq> type;
};
/*
* Base case for recursively defined gradient template.
*/
template <typename Derived, int Nq>
struct Gradient<Derived, Nq, 1> {
typedef typename Eigen::Matrix<typename Derived::Scalar,
Derived::SizeAtCompileTime, Nq> type;
};
} // namespace math
} // namespace drake