29 #ifndef TOON_INCLUDE_SL_H 30 #define TOON_INCLUDE_SL_H 32 #include <TooN/TooN.h> 33 #include <TooN/helpers.h> 34 #include <TooN/gaussian_elimination.h> 35 #include <TooN/determinant.h> 40 template <
int N,
typename P>
class SL;
41 template <
int N,
typename P> std::istream & operator>>(std::istream &,
SL<N, P> &);
56 template <
int N,
typename Precision = DefaultPrecision>
58 friend std::istream &
operator>> <N,Precision>(std::istream &,
SL &);
61 static const int dim = N*N - 1;
64 SL() : my_matrix(Identity) {}
67 template <
int S,
typename P,
typename B>
71 template <
int R,
int C,
typename P,
typename A>
89 template <
int S,
typename P,
typename B>
92 inline Vector<N*N-1, Precision> ln()
const ;
101 SL(
const SL & from,
struct Invert ) {
110 assert(abs(det) > 0);
112 my_matrix /= pow(det, 1.0/N);
118 static const int COUNT_DIAG = N - 1;
119 static const int COUNT_SYMM = (dim - COUNT_DIAG)/2;
120 static const int COUNT_ASYMM = COUNT_SYMM;
121 static const int DIAG_LIMIT = COUNT_DIAG;
122 static const int SYMM_LIMIT = COUNT_SYMM + DIAG_LIMIT;
128 template <
int N,
typename Precision>
129 template <
int S,
typename P,
typename B>
133 for(
int i = 0; i <
dim; ++i)
140 template <
int N,
typename Precision>
145 for(
int i = 0; i < DIAG_LIMIT; ++i){
146 v[i] = l(i,i) + last;
149 for(
int i = DIAG_LIMIT, row = 0, col = 1; i < SYMM_LIMIT; ++i) {
151 v[i] = (l(row, col) + l(col, row))*0.5;
152 v[i+COUNT_SYMM] = (-l(row, col) + l(col, row))*0.5;
162 template <
int N,
typename Precision>
164 assert( i > -1 && i <
dim );
168 result(i+1,i+1) = -1;
169 }
else if(i < SYMM_LIMIT){
170 int row = 0, col = i - DIAG_LIMIT + 1;
171 while(col > (N - row - 1)){
172 col -= (N - row - 1);
176 result(row, col) = result(col, row) = 1;
178 int row = 0, col = i - SYMM_LIMIT + 1;
179 while(col > N - row - 1){
184 result(row, col) = -1;
185 result(col, row) = 1;
190 template <
int S,
typename PV,
typename B,
int N,
typename P>
195 template <
int S,
typename PV,
typename B,
int N,
typename P>
200 template<
int R,
int C,
typename PM,
typename A,
int N,
typename P>
inline 205 template<
int R,
int C,
typename PM,
typename A,
int N,
typename P>
inline 210 template <
int N,
typename P>
211 std::ostream & operator<<(std::ostream & out, const SL<N, P> & h){
212 out << h.get_matrix();
216 template <
int N,
typename P>
217 std::istream & operator>>(std::istream & in,
SL<N, P> & h){
Matrix< R, C, P > exp(const Matrix< R, C, P, B > &m)
computes the matrix exponential of a matrix m by scaling m by 1/(powers of 2), using Taylor series an...
Definition: helpers.h:330
Matrix< R, C, P > log(const Matrix< R, C, P, B > &m)
computes the matrix logarithm of a matrix m using the inverse scaling and squaring method...
Definition: helpers.h:373
const Matrix< N, N, Precision > & get_matrix() const
returns the represented matrix
Definition: sl.h:75
SL operator*=(const SL< N, P > &rhs)
right multiplies this SL with another one
Definition: sl.h:85
Pretty generic SFINAE introspection generator.
Definition: vec_test.cc:21
SL< N, typename Internal::MultiplyType< Precision, P >::type > operator*(const SL< N, P > &rhs) const
multiplies to SLs together by multiplying the underlying matrices
Definition: sl.h:81
SL inverse() const
returns the inverse using LU
Definition: sl.h:77
static const int dim
dimension of the vector space represented by SL<N>
Definition: sl.h:61
static Matrix< N, N, Precision > generator(int)
returns one generator of the group.
Definition: sl.h:163
represents an element from the group SL(n), the NxN matrices M with det(M) = 1.
Definition: sl.h:40
P determinant(const Matrix< R, C, P, B > &A)
Compute the determinant of a matrix using an appropriate method.
Definition: determinant.h:174
Definition: size_mismatch.hh:103
static SL exp(const Vector< S, P, B > &)
exponentiates a vector in the Lie algebra to compute the corresponding element
Vector< N, Precision > gaussian_elimination(Matrix< N, N, Precision > A, Vector< N, Precision > b)
Return the solution for , given and .
Definition: gaussian_elimination.h:43
SL(const Matrix< R, C, P, A > &M)
copy constructor from a matrix, coerces matrix to be of determinant = 1
Definition: sl.h:72
static const int size
size of the matrices represented by SL<N>
Definition: sl.h:60
SL(const Vector< S, P, B > &v)
exp constructor, creates element through exponentiation of Lie algebra vector. see SL::exp...
Definition: sl.h:68
SL()
default constructor, creates identity element
Definition: sl.h:64