toon-members
[Top][All Lists]
Advanced

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

[Toon-members] TooN operators.h internal/matrix.hh internal/mb...


From: Edward Rosten
Subject: [Toon-members] TooN operators.h internal/matrix.hh internal/mb...
Date: Sat, 07 Feb 2009 15:32:56 +0000

CVSROOT:        /cvsroot/toon
Module name:    TooN
Changes by:     Edward Rosten <edrosten>        09/02/07 15:32:56

Modified files:
        .              : operators.h 
        internal       : matrix.hh mbase.hh 
        test           : mat_test2.cc 

Log message:
        Matrix now takes a class with a member template, as opposed to a 
template
        directly, so it is much nicer to write user functions accepting Matrix.
        
        Now it is:
        
        template<class B> void do_something(Matrix<2,2,double,B> m);

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/TooN/operators.h?cvsroot=toon&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/matrix.hh?cvsroot=toon&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/mbase.hh?cvsroot=toon&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/TooN/test/mat_test2.cc?cvsroot=toon&r1=1.3&r2=1.4

Patches:
Index: operators.h
===================================================================
RCS file: /cvsroot/toon/TooN/operators.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- operators.h 26 Jan 2009 18:41:42 -0000      1.3
+++ operators.h 7 Feb 2009 15:32:56 -0000       1.4
@@ -75,7 +75,7 @@
 }
 
 
-template<int Rows, int Cols, typename Precision, template<int, int, class> 
class Base>
+template<int Rows, int Cols, typename Precision, class Base>
 inline std::ostream& operator<< (std::ostream& os, const Matrix<Rows, Cols, 
Precision, Base>& m){
        for(int i=0; i < m.num_rows(); i++)
        {

Index: internal/matrix.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/matrix.hh,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- internal/matrix.hh  7 Feb 2009 15:16:54 -0000       1.6
+++ internal/matrix.hh  7 Feb 2009 15:32:56 -0000       1.7
@@ -1,26 +1,26 @@
-template <int Rows=-1, int Cols=Rows, class Precision=double, template<int R, 
int C, class P> class Layout = RowMajor>
-class Matrix : public Layout<Rows, Cols, Precision>
+template <int Rows=-1, int Cols=Rows, class Precision=double, class Layout = 
RowMajor>
+class Matrix : public Layout::template Layout<Rows, Cols, Precision>
 {
   private:
-       using Layout<Rows, Cols, Precision>::my_data;
+       using Layout::template Layout<Rows, Cols, Precision>::my_data;
   public:
        //Use Tom's sneaky constructor hack...
                
        Matrix(){}
 
        Matrix(Precision* data, Slicing)
-       :Layout<Rows, Cols, Precision>(data){}
+       :Layout::template Layout<Rows, Cols, Precision>(data){}
        
        //The stride is always passed during a slice. If it is not
        //needed, it will be ignored later and not stored.
        Matrix(Precision* data, int stride, Slicing)
-       :Layout<Rows, Cols, Precision>(data, stride){}
+       :Layout::template Layout<Rows, Cols, Precision>(data, stride){}
 
        Matrix(Precision* data, int rows, int cols, int stride, Slicing)
-       :Layout<Rows, Cols, Precision>(data, rows, cols, stride){}
+       :Layout::template Layout<Rows, Cols, Precision>(data, rows, cols, 
stride){}
 
        Matrix(int rows, int cols)
-       :Layout<Rows,Cols,Precision>(rows, cols)
+       :Layout::template Layout<Rows,Cols,Precision>(rows, cols)
        {}
 
        Precision* data() {

Index: internal/mbase.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/mbase.hh,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- internal/mbase.hh   7 Feb 2009 15:16:54 -0000       1.6
+++ internal/mbase.hh   7 Feb 2009 15:32:56 -0000       1.7
@@ -21,7 +21,7 @@
 // The new case is that for strides, -2 means that the stride is 
 // the same as num_cols/num_rows, which must be dynamically sized.
 
-template<int,int,class,template<int,int,class> class> class Matrix;
+template<int,int,class,class> class Matrix;
 template<int Rows, int Cols, class Precision, int Stride, class Mem> struct 
GenericRowMajor;
 
 //Closure used to acquire strides
@@ -29,43 +29,49 @@
 //-2 means dynamic stride is tied to size
 template<int Stride> struct Slice
 {
-       template<int Rows, int Cols, class Precision> struct RowMajor: public 
GenericRowMajor<Rows, Cols, Precision, Stride, MatrixSlice<Rows, Cols, 
Precision> >
+       struct RowMajor
+       {
+               template<int Rows, int Cols, class Precision> struct Layout: 
public GenericRowMajor<Rows, Cols, Precision, Stride, MatrixSlice<Rows, Cols, 
Precision> >
        {
                //Optional constructors.
                
-               RowMajor(Precision* p)
+                       Layout(Precision* p)
                :GenericRowMajor<Rows,Cols,Precision,Stride,MatrixSlice<Rows, 
Cols, Precision> >(p)
                {
                }
 
-               RowMajor(Precision* p, int stride)
+                       Layout(Precision* p, int stride)
                :GenericRowMajor<Rows,Cols,Precision,Stride,MatrixSlice<Rows, 
Cols, Precision> >(p, stride)
                {
                }
 
-               RowMajor(Precision* p, int rows, int cols)
+                       Layout(Precision* p, int rows, int cols)
                :GenericRowMajor<Rows,Cols,Precision,Stride,MatrixSlice<Rows, 
Cols, Precision> >(p, rows, cols)
                {
                }
 
-               RowMajor(Precision* p, int rows, int cols, int stride)
+                       Layout(Precision* p, int rows, int cols, int stride)
                :GenericRowMajor<Rows,Cols,Precision,Stride,MatrixSlice<Rows, 
Cols, Precision> >(p, rows, cols, stride)
                {
                }
 
        };
+       };
 };
 
 
-template<int Rows, int Cols, class Precision> struct RowMajor: public 
GenericRowMajor<Rows, Cols, Precision, (Cols==-1?-2:Cols), MatrixAlloc<Rows, 
Cols, Precision> >
+struct RowMajor
 {
+       template<int Rows, int Cols, class Precision> struct Layout: public 
GenericRowMajor<Rows, Cols, Precision, (Cols==-1?-2:Cols), MatrixAlloc<Rows, 
Cols, Precision> >
+       {
        //Optional constructors.
        
-       RowMajor(){}
+               Layout(){}
 
-       RowMajor(int rows, int cols)
+               Layout(int rows, int cols)
        :GenericRowMajor<Rows, Cols, Precision, (Cols == -1 ? -2 : Cols), 
MatrixAlloc<Rows, Cols, Precision> >(rows, cols)
        {}
+       };
 };
 
 
@@ -186,14 +192,14 @@
        }
 
        template<int Rstart, int Cstart, int Rlength, int Clength>
-       Matrix<Rlength, Clength, Precision, Slice<SliceStride>::template 
RowMajor> slice()
+       Matrix<Rlength, Clength, Precision, typename 
Slice<SliceStride>::RowMajor> slice()
        {
                //Always pass the stride as a run-time parameter. It will be 
ignored
                //by SliceHolder (above) if it is statically determined.
-               return Matrix<Rlength, Clength, Precision, 
Slice<SliceStride>::template RowMajor>(my_data+stride()*Rstart + Cstart, 
stride(), Slicing());
+               return Matrix<Rlength, Clength, Precision, typename 
Slice<SliceStride>::RowMajor>(my_data+stride()*Rstart + Cstart, stride(), 
Slicing());
        }
 
-       Matrix<-1, -1, Precision, Slice<SliceStride>::template RowMajor > 
slice(int rs, int cs, int rl, int cl){
-               return Matrix<-1, -1, Precision, Slice<SliceStride>::template 
RowMajor >(my_data+stride()*rs +cs, rl, cl, stride(), Slicing());
+       Matrix<-1, -1, Precision, typename Slice<SliceStride>::RowMajor > 
slice(int rs, int cs, int rl, int cl){
+               return Matrix<-1, -1, Precision, typename 
Slice<SliceStride>::RowMajor >(my_data+stride()*rs +cs, rl, cl, stride(), 
Slicing());
        }
 };

Index: test/mat_test2.cc
===================================================================
RCS file: /cvsroot/toon/TooN/test/mat_test2.cc,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- test/mat_test2.cc   7 Feb 2009 15:16:55 -0000       1.3
+++ test/mat_test2.cc   7 Feb 2009 15:32:56 -0000       1.4
@@ -2,7 +2,7 @@
 using namespace TooN;
 using namespace std;
 
-template<int R, int C, template<int,int,class> class B> void 
statictest(Matrix<R,C,double,B> m)
+template<int R, int C, class B> void statictest(Matrix<R,C,double,B> m)
 {
        for(int i=0; i < 12; i++)
                (&m[0][0])[i] = i;
@@ -33,7 +33,7 @@
        cout << endl;
 }
 
-template<int R, int C, template<int,int,class> class B> void 
staticdynamictest(Matrix<R,C,double,B> m)
+template<int R, int C, class B> void staticdynamictest(Matrix<R,C,double,B> m)
 {
        for(int i=0; i < 12; i++)
                (&m[0][0])[i] = i;




reply via email to

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