toon-members
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Toon-members] TooN determinant.h functions/fadbad.h


From: Gerhard Reitmayr
Subject: [Toon-members] TooN determinant.h functions/fadbad.h
Date: Thu, 21 Apr 2011 12:14:16 +0000

CVSROOT:        /cvsroot/toon
Module name:    TooN
Changes by:     Gerhard Reitmayr <gerhard>      11/04/21 12:14:16

Modified files:
        .              : determinant.h 
        functions      : fadbad.h 

Log message:
        make determinant.h Precision clean, extend fadbad interface

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/TooN/determinant.h?cvsroot=toon&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/TooN/functions/fadbad.h?cvsroot=toon&r1=1.1&r2=1.2

Patches:
Index: determinant.h
===================================================================
RCS file: /cvsroot/toon/TooN/determinant.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- determinant.h       7 Apr 2010 14:48:07 -0000       1.5
+++ determinant.h       21 Apr 2011 12:14:15 -0000      1.6
@@ -85,7 +85,7 @@
                        Precision maxval = abs(A[i][i]);
                        
                        for (int ii=i+1; ii<size; ++ii) {
-                               double v =  abs(A[ii][i]);
+                               Precision v =  abs(A[ii][i]);
                                if (v > maxval) {
                                        maxval = v;
                                        argmax = ii;
@@ -111,7 +111,7 @@
                        for (int u=i+1; u<size; ++u) {
                                //Do not multiply out the usual 1/pivot term
                                //to avoid division. It causes poor scaling.
-                               double factor = A[u][i]/pivot;
+                               Precision factor = A[u][i]/pivot;
 
                                for (int j=i+1; j<size; ++j)
                                        A[u][j] = A[u][j] - factor * A[i][j];

Index: functions/fadbad.h
===================================================================
RCS file: /cvsroot/toon/TooN/functions/fadbad.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- functions/fadbad.h  18 Apr 2010 09:49:18 -0000      1.1
+++ functions/fadbad.h  21 Apr 2011 12:14:16 -0000      1.2
@@ -45,6 +45,11 @@
        return out << val.val();
 }
 
+template <typename P>
+inline F<P> abs( const F<P> & val ){
+    return (val.val() < 0) ? -val : val;
+}
+
 }
 
 namespace TooN {
@@ -54,12 +59,20 @@
        static const int value = numeric_limits<C>::is_specialized; ///<Is C a 
field?
 };
 
+template <int N, typename T, typename A>
+inline Vector<N, T> get_value( const Vector<N, fadbad::F<T>, A> & v ){
+    Vector<N,T> result(v.size());
+    for(int i = 0; i < result.size(); ++i)
+        result[i] = v[i].val();
+    return result;
+}
+
 template <int N> 
 inline Vector<N, fadbad::F<double> > make_fad_vector( const Vector<N, double> 
& val, const int start = 0, const int size = N ){
        using std::min;
        Vector<N, fadbad::F<double> > result = val;
-       for(int i = start; i < min(size, start+N); ++i)
-               result[i].diff(i,size);
+       for(int i = 0, d = start; i < val.size() && d < size; ++i, ++d)
+               result[i].diff(d,size);
        return result;
 }
 
@@ -88,40 +101,40 @@
        return result;
 }
 
-inline SO3<fadbad::F<double> > make_fad_so3(){
-       const Vector<3, fadbad::F<double> > p = make_fad_vector(makeVector(0.0, 
0, 0));
+inline SO3<fadbad::F<double> > make_fad_so3(int start = 0, int size = 3){
+       const Vector<3, fadbad::F<double> > p = make_fad_vector(makeVector(0.0, 
0, 0), start, size);
        return SO3<fadbad::F<double> >(p);
 }
 
-inline SE3<fadbad::F<double> > make_fad_se3(){
-       const Vector<6, fadbad::F<double> > p = make_fad_vector(makeVector(0.0, 
0, 0, 0, 0, 0));
+inline SE3<fadbad::F<double> > make_fad_se3( int start = 0, int size = 6){
+       const Vector<6, fadbad::F<double> > p = make_fad_vector(makeVector(0.0, 
0, 0, 0, 0, 0), start, size);
        return SE3<fadbad::F<double> >(p);
 }
 
-inline SE2<fadbad::F<double> > make_fad_se2() {
-       return SE2<fadbad::F<double> >(make_fad_vector(makeVector(0.0, 0, 0)));
+inline SE2<fadbad::F<double> > make_fad_se2(int start = 0, int size = 3) {
+       return SE2<fadbad::F<double> >(make_fad_vector(makeVector(0.0, 0, 0), 
start, size));
 }
 
-inline SO2<fadbad::F<double> > make_fad_so2() {
+inline SO2<fadbad::F<double> > make_fad_so2(int start = 0, int size = 1) {
        fadbad::F<double> r = 0.0;
-       r.diff(0,1) = 1.0;
+       r.diff(start,size) = 1.0;
        return SO2<fadbad::F<double> >(r);
 }
 
-inline SO3<fadbad::F<double> > make_left_fad_so3( const SO3<double> & r ){
-       return make_fad_so3() * r;
+inline SO3<fadbad::F<double> > make_left_fad_so3( const SO3<double> & r, int 
start = 0, int size = 3 ){
+       return make_fad_so3(start, size) * r;
 }
 
-inline SE3<fadbad::F<double> > make_left_fad_se3( const SE3<double> & t ){
-       return make_fad_se3() * t;
+inline SE3<fadbad::F<double> > make_left_fad_se3( const SE3<double> & t,  int 
start = 0, int size = 6 ){
+       return make_fad_se3(start, size) * t;
 }
 
-inline SO2<fadbad::F<double> > make_left_fad_so2( const SO2<double> & r ){
-       return make_fad_so2() * r;
+inline SO2<fadbad::F<double> > make_left_fad_so2( const SO2<double> & r, int 
start = 0, int size = 1 ){
+       return make_fad_so2(start, size) * r;
 }
 
-inline SE2<fadbad::F<double> > make_left_fad_se2( const SE2<double> & t ){
-       return make_fad_se2() * t;
+inline SE2<fadbad::F<double> > make_left_fad_se2( const SE2<double> & t, int 
start = 0, int size = 3 ){
+       return make_fad_se2(start, size) * t;
 }
 
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]