toon-members
[Top][All Lists]
Advanced

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

[Toon-members] TooN TooN.h vbase.hh vclasses.hh doc/SVDdoc.h v...


From: Tom Drummond
Subject: [Toon-members] TooN TooN.h vbase.hh vclasses.hh doc/SVDdoc.h v...
Date: Mon, 17 Jul 2006 14:15:51 +0000

CVSROOT:        /cvsroot/toon
Module name:    TooN
Changes by:     Tom Drummond <twd20>    06/07/17 14:15:50

Modified files:
        .              : TooN.h vbase.hh vclasses.hh 
        doc            : SVDdoc.h 
Added files:
        .              : vmagic.hh 

Log message:
        changes to vector magic
        
        - moved logic into a new file called vmagic.hh
        - added logic to FixedVector<...> base class to allow assignment to
        arbitrary FixedVectors (e.g. M[0] for a matrix)
        - moved logic for insertion style operations into FixedVector
        - removed unneccessary template parameter from VectorCreator
        
        twd20

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/TooN/TooN.h?cvsroot=toon&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/TooN/vbase.hh?cvsroot=toon&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/TooN/vclasses.hh?cvsroot=toon&r1=1.21&r2=1.22
http://cvs.savannah.gnu.org/viewcvs/TooN/vmagic.hh?cvsroot=toon&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/TooN/doc/SVDdoc.h?cvsroot=toon&r1=1.3&r2=1.4

Patches:
Index: TooN.h
===================================================================
RCS file: /cvsroot/toon/TooN/TooN.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- TooN.h      24 May 2006 17:05:28 -0000      1.8
+++ TooN.h      17 Jul 2006 14:15:50 -0000      1.9
@@ -187,6 +187,7 @@
   #define TOON_THROW throw()
 #endif
 
+#include <TooN/vmagic.hh>
 
 #include <TooN/membase.hh>
 #include <TooN/vbase.hh>

Index: vbase.hh
===================================================================
RCS file: /cvsroot/toon/TooN/vbase.hh,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- vbase.hh    22 Nov 2005 17:10:07 -0000      1.11
+++ vbase.hh    17 Jul 2006 14:15:50 -0000      1.12
@@ -80,6 +80,33 @@
     VectorCopy<Accessor, Accessor2>::eval(*this, from);
     return *this;
   }
+
+  // assignment from a double - uses vector magic
+  VectorMagic::VectorFiller<1,Size, FixedVector<Size, Accessor>, 
VectorMagic::CommaStyle> operator=(double t) {
+    (*this)[0] = t;
+    return VectorMagic::VectorFiller<1,Size, FixedVector<Size, Accessor>, 
VectorMagic::CommaStyle>(*this);
+  }
+
+  // insertion operators - uses vector magic
+  VectorMagic::VectorFiller<1,Size, FixedVector<Size,Accessor>, 
VectorMagic::InsertionStyle> operator<<(double t) {
+    (*this)[0] = t;
+    return VectorMagic::VectorFiller<1,Size, FixedVector<Size,Accessor>, 
VectorMagic::InsertionStyle>(*this);
+  }
+
+  template <int N> VectorMagic::VectorFiller<N,Size, 
FixedVector<Size,Accessor>, VectorMagic::InsertionStyle> operator<<(const 
VectorMagic::ComponentPlaceHolder<N>& t) {
+    return VectorMagic::VectorFiller<N,Size, FixedVector<Size,Accessor>, 
VectorMagic::InsertionStyle>(*this);
+  }
+  
+  template <int N> VectorMagic::VectorFiller<N,Size, 
FixedVector<Size,Accessor>, VectorMagic::InsertionStyle> operator<<(const 
Vector<N>& t) {
+    (*this).template slice<0,N>() = t;
+    return VectorMagic::VectorFiller<N,Size, FixedVector<Size,Accessor>, 
VectorMagic::InsertionStyle>(*this);
+  }
+
+
+
+
+
+
 };
 
 template <class Accessor>

Index: vclasses.hh
===================================================================
RCS file: /cvsroot/toon/TooN/vclasses.hh,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -b -r1.21 -r1.22
--- vclasses.hh 9 Feb 2006 11:12:05 -0000       1.21
+++ vclasses.hh 17 Jul 2006 14:15:50 -0000      1.22
@@ -27,126 +27,6 @@
 //                       //
 ///////////////////////////
 
-namespace VectorMagic {
-  template <int N=1>
-  struct ComponentPlaceHolder {
-  };
-
-  struct InsertionStyle {};
-  struct CommaStyle {};
-
-
-  template<bool Good> struct sentinel
-  {
-       typedef int too_many_elements_inserted;
-  };
-
-  template<> struct sentinel<false>
-  {
-  };
-
-  template <int Index, int Limit, class Vec, class Style> struct VectorFiller;
-  template <int Index, int Limit, class Vec> struct 
VectorFiller<Index,Limit,Vec,CommaStyle> {
-
-
-    // a static assertion
-    typedef typename sentinel<(Limit >= Index)>::too_many_elements_inserted 
dummy; 
-  
-    Vec& v;
-    bool final_initializer_but_Vector_not_filled;
-    inline VectorFiller(Vec& vec) : v(vec), 
final_initializer_but_Vector_not_filled(Index!=Limit) {}
-    template <class T> inline VectorFiller<Index+1,Limit,Vec,CommaStyle> 
operator,(const T& t) {
-      v[Index] = t;
-      final_initializer_but_Vector_not_filled = false;
-      return VectorFiller<Index+1,Limit,Vec,CommaStyle>(v);
-    }
-    template <int N> inline VectorFiller<Index+N,Limit,Vec,CommaStyle> 
operator,(const ComponentPlaceHolder<N>& ph) {
-      final_initializer_but_Vector_not_filled = false;
-      return (VectorFiller<Index+1,Limit,Vec,CommaStyle>(v), 
ComponentPlaceHolder<N-1>());
-    }
-    inline VectorFiller<Index+1,Limit,Vec,CommaStyle> operator,(const 
ComponentPlaceHolder<1>& ph) {
-      final_initializer_but_Vector_not_filled = false;
-      return VectorFiller<Index+1,Limit,Vec,CommaStyle>(v);
-    }
-    inline ~VectorFiller() {
-      assert(!final_initializer_but_Vector_not_filled);
-    }
-    inline operator Vec () const { return v; }
-  };
-  
-  template <int Index, int Limit, class Vec> struct 
VectorFiller<Index,Limit,Vec,InsertionStyle> {
-       typedef typename sentinel<(Limit >= Index)>::too_many_elements_inserted 
dummy; 
-    Vec& v;
-    inline VectorFiller(Vec& vec) : v(vec){}
-
-    template <int T> inline VectorFiller<Index+T,Limit,Vec,InsertionStyle> 
operator<<(const Vector<T>& t) {
-      v.template slice<Index,T>() = t;
-      return VectorFiller<Index+T,Limit,Vec,InsertionStyle>(v);
-    }
-
-    template <class T> inline VectorFiller<Index+1,Limit,Vec,InsertionStyle> 
operator<<(const T& t) {
-      v[Index] = t;
-      return VectorFiller<Index+1,Limit,Vec,InsertionStyle>(v);
-    }
-    template <int N> inline VectorFiller<Index+N,Limit,Vec,InsertionStyle> 
operator<<(const ComponentPlaceHolder<N>& ph) {
-      return (VectorFiller<Index+1,Limit,Vec,InsertionStyle>(v) << 
ComponentPlaceHolder<N-1>());
-    }
-    inline VectorFiller<Index+1,Limit,Vec,InsertionStyle> operator<<(const 
ComponentPlaceHolder<1>& ph) {
-      return VectorFiller<Index+1,Limit,Vec,InsertionStyle>(v);
-    }
-    inline operator Vec () const { return v; }
-  };
-/*
-  template <int Index, class Vec> struct VectorFiller<Index, Index, Vec, 
CommaStyle> {
-    Vec& v;
-    inline VectorFiller(Vec& vec) : v(vec) {}
-    template <class T> inline void operator,(const T& t) const { 
too_many_elements_given(); }
-    inline operator Vec () const { return v; }
-  };
-
-  template <int Index, class Vec> struct VectorFiller<Index, Index, Vec, 
InsertionStyle> {
-    Vec& v;
-    inline VectorFiller(Vec& vec) : v(vec) {}
-    template <class T> inline void operator,(const T& t) const { 
too_many_elements_given(); }
-    inline operator Vec () const { return v; }
-  };
-*/
-  template <class Left, int Size, class Val> struct VectorCreator
-  {
-    const Left& left;
-    const Val& val;
-    VectorCreator(const Left& l, const Val& v) : left(l), val(v) { }
-    template <class T> VectorCreator<VectorCreator<Left,Size,Val>, Size+1, T> 
operator,(const T& t) const {
-      return VectorCreator<VectorCreator<Left,Size,Val>, Size+1, T>(*this, t);
-    }
-    template <class V> void assign(V& v) const { v[Size-1] = val; 
left.assign(v); }
-    operator Vector<Size> () const {
-      Vector<Size> v;
-      assign(v);
-      return v;
-    }
-  };
-
-  struct BaseVectorCreator
-  {
-    template <class T> inline VectorCreator<BaseVectorCreator, 1, T> 
operator,(const T& t) const {
-      return VectorCreator<BaseVectorCreator, 1, T>(*this, t);
-    }
-    template <class V> inline void assign(V& ) const {}
-  };
-}
-
-static VectorMagic::BaseVectorCreator make_Vector;
-
-namespace VectorMagic 
-{
-  inline void dummy_make_Vector_user() { int i; make_Vector.assign(i); }
-}
-
-template <int N> VectorMagic::ComponentPlaceHolder<N> no_change() { return 
VectorMagic::ComponentPlaceHolder<N>(); }
-inline VectorMagic::ComponentPlaceHolder<1> no_change() { return 
VectorMagic::ComponentPlaceHolder<1>(); }
-  
-
 template <int Size>
 class Vector : public FixedVector<Size, FixedVAccessor<Size,typename 
SizeTraits<Size>::get_zone> > {
  public:
@@ -194,37 +74,27 @@
     return *this;
   }
 
+
+  // vector magic assignment operators (uses comma style) - insertion style 
defined in vbase.hh
+  VectorMagic::VectorFiller<1,Size, Vector<Size>, VectorMagic::CommaStyle> 
operator=(double t) {
+    (*this)[0] = t;
+    return VectorMagic::VectorFiller<1,Size, Vector<Size>, 
VectorMagic::CommaStyle>(*this);
+  }
+
   template <int N> VectorMagic::VectorFiller<N,Size, 
Vector<Size>,VectorMagic::CommaStyle> operator=(const 
VectorMagic::ComponentPlaceHolder<N>& t) {
     return VectorMagic::VectorFiller<N,Size, 
Vector<Size>,VectorMagic::CommaStyle>(*this);
   }
        
-  template<class A, int I, class B> Vector<Size>& operator=(const 
VectorMagic::VectorCreator<A,I,B>& v)
+  template<class A, int I> Vector<Size>& operator=(const 
VectorMagic::VectorCreator<A,I>& v)
   {
        *this = (Vector<Size>)v;
        return *this;
   }
 
+};
 
-  VectorMagic::VectorFiller<1,Size, Vector<Size>, VectorMagic::CommaStyle> 
operator=(double t) {
-    (*this)[0] = t;
-    return VectorMagic::VectorFiller<1,Size, Vector<Size>, 
VectorMagic::CommaStyle>(*this);
-  }
-
-  template <int N> VectorMagic::VectorFiller<N,Size, Vector<Size>, 
VectorMagic::InsertionStyle> operator<<(const 
VectorMagic::ComponentPlaceHolder<N>& t) {
-    return VectorMagic::VectorFiller<N,Size, Vector<Size>, 
VectorMagic::InsertionStyle>(*this);
-  }
-
-  VectorMagic::VectorFiller<1,Size, Vector<Size>, VectorMagic::InsertionStyle> 
operator<<(double t) {
-    (*this)[0] = t;
-    return VectorMagic::VectorFiller<1,Size, Vector<Size>, 
VectorMagic::InsertionStyle>(*this);
-  }
   
-  template <int N> VectorMagic::VectorFiller<N,Size, Vector<Size>, 
VectorMagic::InsertionStyle> operator<<(const Vector<N>& t) {
-    (*this).template slice<0,N>() = t;
-    return VectorMagic::VectorFiller<N,Size, Vector<Size>, 
VectorMagic::InsertionStyle>(*this);
-  }
 
-};
 
 
 template <>

Index: doc/SVDdoc.h
===================================================================
RCS file: /cvsroot/toon/TooN/doc/SVDdoc.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- doc/SVDdoc.h        7 Jul 2006 14:24:20 -0000       1.3
+++ doc/SVDdoc.h        17 Jul 2006 14:15:50 -0000      1.4
@@ -74,6 +74,9 @@
        /// performs the decomposition immediately.
        SVD(const Matrix<Rows,Cols>& M);
 
+       /// Compute the %SVD decomposition of M, typically used after the 
default constructor
+       void compute(const Matrix<Rows,Cols>& M);
+
        /// Calculate result of multiplying the (pseudo-)inverse of M by 
another matrix. 
        /// For a matrix \f$A\f$, this calculates \f$M^{\dagger}A\f$ by back 
substitution 
        /// (i.e. without explictly calculating the (pseudo-)inverse). 

Index: vmagic.hh
===================================================================
RCS file: vmagic.hh
diff -N vmagic.hh
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ vmagic.hh   17 Jul 2006 14:15:50 -0000      1.1
@@ -0,0 +1,107 @@
+
+namespace VectorMagic {
+  template <int N=1>
+  struct ComponentPlaceHolder {
+  };
+
+  struct InsertionStyle {};
+  struct CommaStyle {};
+
+
+  template<bool Good> struct sentinel
+  {
+       typedef int too_many_elements_inserted;
+  };
+
+  template<> struct sentinel<false>
+  {
+  };
+
+  template <int Index, int Limit, class Vec, class Style> struct VectorFiller;
+  template <int Index, int Limit, class Vec> struct 
VectorFiller<Index,Limit,Vec,CommaStyle> {
+
+
+    // a static assertion
+    typedef typename sentinel<(Limit >= Index)>::too_many_elements_inserted 
dummy; 
+  
+    Vec& v;
+    bool final_initializer_but_Vector_not_filled;
+    inline VectorFiller(Vec& vec) : v(vec), 
final_initializer_but_Vector_not_filled(Index!=Limit) {}
+
+    inline VectorFiller<Index+1,Limit,Vec,CommaStyle> operator,(double t) {
+      v[Index] = t;
+      final_initializer_but_Vector_not_filled = false;
+      return VectorFiller<Index+1,Limit,Vec,CommaStyle>(v);
+    }
+    template <int N> inline VectorFiller<Index+N,Limit,Vec,CommaStyle> 
operator,(const ComponentPlaceHolder<N>& ph) {
+      final_initializer_but_Vector_not_filled = false;
+      return (VectorFiller<Index+1,Limit,Vec,CommaStyle>(v), 
ComponentPlaceHolder<N-1>());
+    }
+    inline VectorFiller<Index+1,Limit,Vec,CommaStyle> operator,(const 
ComponentPlaceHolder<1>& ph) {
+      final_initializer_but_Vector_not_filled = false;
+      return VectorFiller<Index+1,Limit,Vec,CommaStyle>(v);
+    }
+    inline ~VectorFiller() {
+      assert(!final_initializer_but_Vector_not_filled);
+    }
+    inline operator Vec () const { return v; }
+  };
+  
+  template <int Index, int Limit, class Vec> struct 
VectorFiller<Index,Limit,Vec,InsertionStyle> {
+       typedef typename sentinel<(Limit >= Index)>::too_many_elements_inserted 
dummy; 
+    Vec& v;
+    inline VectorFiller(Vec& vec) : v(vec){}
+
+    template <int N> inline VectorFiller<Index+N,Limit,Vec,InsertionStyle> 
operator<<(const Vector<N>& t) {
+      v.template slice<Index,N>() = t;
+      return VectorFiller<Index+N,Limit,Vec,InsertionStyle>(v);
+    }
+
+    inline VectorFiller<Index+1,Limit,Vec,InsertionStyle> operator<<(double t) 
{
+      v[Index] = t;
+      return VectorFiller<Index+1,Limit,Vec,InsertionStyle>(v);
+    }
+    template <int N> inline VectorFiller<Index+N,Limit,Vec,InsertionStyle> 
operator<<(const ComponentPlaceHolder<N>& ph) {
+      return (VectorFiller<Index+1,Limit,Vec,InsertionStyle>(v) << 
ComponentPlaceHolder<N-1>());
+    }
+    inline VectorFiller<Index+1,Limit,Vec,InsertionStyle> operator<<(const 
ComponentPlaceHolder<1>& ph) {
+      return VectorFiller<Index+1,Limit,Vec,InsertionStyle>(v);
+    }
+    inline operator Vec () const { return v; }
+  };
+
+
+  template <class Left, int Size> struct VectorCreator
+  {
+    const Left& left;
+    double val;
+    VectorCreator(const Left& l, double v) : left(l), val(v) { }
+    VectorCreator<VectorCreator<Left,Size>, Size+1> operator,(double t) const {
+      return VectorCreator<VectorCreator<Left,Size>, Size+1>(*this, t);
+    }
+    template <class V> void assign(V& v) const { v[Size-1] = val; 
left.assign(v); }
+    operator Vector<Size> () const {
+      Vector<Size> v;
+      assign(v);
+      return v;
+    }
+  };
+
+  struct BaseVectorCreator
+  {
+    inline VectorCreator<BaseVectorCreator, 1> operator,(double t) const {
+      return VectorCreator<BaseVectorCreator, 1>(*this, t);
+    }
+    template <class V> inline void assign(V& ) const {}
+  };
+}
+
+static VectorMagic::BaseVectorCreator make_Vector;
+
+namespace VectorMagic 
+{
+  inline void dummy_make_Vector_user() { int i; make_Vector.assign(i); }
+}
+
+template <int N> VectorMagic::ComponentPlaceHolder<N> no_change() { return 
VectorMagic::ComponentPlaceHolder<N>(); }
+inline VectorMagic::ComponentPlaceHolder<1> no_change() { return 
VectorMagic::ComponentPlaceHolder<1>(); }




reply via email to

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