toon-members
[Top][All Lists]

## [Toon-members] TooN helpers.h

 From: Gerhard Reitmayr Subject: [Toon-members] TooN helpers.h Date: Tue, 12 Jun 2007 18:29:53 +0000

```CVSROOT:        /cvsroot/toon
Module name:    TooN
Changes by:     Gerhard Reitmayr <gerhard>      07/06/12 18:29:53

Modified files:
.              : helpers.h

Log message:
more combinations of fixed and dynamic matrices for transformCovariance

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/TooN/helpers.h?cvsroot=toon&r1=1.19&r2=1.20

Patches:
Index: helpers.h
===================================================================
RCS file: /cvsroot/toon/TooN/helpers.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -b -r1.19 -r1.20
--- helpers.h   14 May 2007 21:04:40 -0000      1.19
+++ helpers.h   12 Jun 2007 18:29:53 -0000      1.20
@@ -317,15 +317,56 @@
}
}
}
+
+     template <class F, int R, int N, class A1, class A2, class MatM> inline
void transformCovariance(const FixedMatrix<R,N,A1> & A, const DynamicMatrix<A2>
& B, MatM& M)
+     {
+       assert(M.num_rows() == R &&
+              M.num_cols() == R &&
+              B.num_rows() == N &&
+              B.num_cols() == N);
+       for (int i=0; i<R; ++i) {
+            const Vector<N> ABi = B * A[i];
+            F::eval(M[i][i], ABi * A[i]);
+            for (int j=i+1; j<R; ++j){
+               const double v = ABi * A[j];
+               F::eval(M[j][i], v);
+               F::eval(M[i][j], v);
+            }
+        }
}

- template <class A1, class A2> Matrix<> inline transformCovariance(const
DynamicMatrix<A1> & A, const A2 & B)
+     template <class F, int R, int N, class A1, class A2, class A3> inline
void transformCovariance(const FixedMatrix<R,N,A1> & A, const
FixedMatrix<N,N,A2> & B, DynamicMatrix<A3> & M)
+     {
+       assert(M.num_rows() == R &&
+              M.num_cols() == R );
+       for (int i=0; i<R; ++i) {
+            const Vector<N> ABi = B * A[i];
+            F::eval(M[i][i], ABi * A[i]);
+            for (int j=i+1; j<R; ++j){
+               const double v = ABi * A[j];
+               F::eval(M[j][i], v);
+               F::eval(M[i][j], v);
+            }
+        }
+     }
+
+ }
+
+ template <class A1, class A2> inline Matrix<> transformCovariance(const
DynamicMatrix<A1> & A, const A2 & B)
{
Matrix<> M(A.num_rows(), A.num_rows());
util::transformCovariance<util::Assign>(A,B,M);
return M;
}

+template <int R, int N, class A1, class A2> inline Matrix<R>
transformCovariance(const FixedMatrix<R, N, A1> & A, const DynamicMatrix<A2> &
B)
+ {
+     assert(B.num_cols() == N && B.num_rows() == N);
+     Matrix<R> M;
+     util::transformCovariance<util::Assign>(A,B,M);
+     return M;
+ }
+
template <int R, int N, class Accessor1, class Accessor2> inline Matrix<R>
transformCovariance(const FixedMatrix<R,N,Accessor1>& A, const
FixedMatrix<N,N,Accessor2>& B)
{
Matrix<R> M;

```