toon-members
[Top][All Lists]
Advanced

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

[Toon-members] TooN internal/allocator.hh internal/matrix.hh i...


From: Edward Rosten
Subject: [Toon-members] TooN internal/allocator.hh internal/matrix.hh i...
Date: Sat, 07 Feb 2009 15:16:55 +0000

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

Modified files:
        internal       : allocator.hh matrix.hh mbase.hh 
        test           : mat_test2.cc 

Log message:
        All combinations of static and dynamic slicing on static and dynamic
        matrices compile.

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

Patches:
Index: internal/allocator.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/allocator.hh,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- internal/allocator.hh       7 Feb 2009 13:32:24 -0000       1.4
+++ internal/allocator.hh       7 Feb 2009 15:16:54 -0000       1.5
@@ -135,8 +135,8 @@
        const int my_rows;
        const int my_cols;
 
-       MatrixSlice(Precision d, int r, int c)
-       :my_data(d), my_rows(r),my_cols(c),my_data(d)
+       MatrixSlice(Precision* d, int r, int c)
+       :my_data(d), my_rows(r),my_cols(c)
        {
        }
 

Index: internal/matrix.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/matrix.hh,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- internal/matrix.hh  7 Feb 2009 13:32:24 -0000       1.5
+++ internal/matrix.hh  7 Feb 2009 15:16:54 -0000       1.6
@@ -16,6 +16,8 @@
        Matrix(Precision* data, int stride, Slicing)
        :Layout<Rows, Cols, Precision>(data, stride){}
 
+       Matrix(Precision* data, int rows, int cols, int stride, Slicing)
+       :Layout<Rows, Cols, Precision>(data, rows, cols, stride){}
 
        Matrix(int rows, int cols)
        :Layout<Rows,Cols,Precision>(rows, cols)

Index: internal/mbase.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/mbase.hh,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- internal/mbase.hh   7 Feb 2009 13:32:24 -0000       1.5
+++ internal/mbase.hh   7 Feb 2009 15:16:54 -0000       1.6
@@ -161,6 +161,9 @@
        GenericRowMajor(Precision* p, int r, int c)
        :Mem(p, r, c) {}
 
+       GenericRowMajor(Precision* p, int r, int c, int stride)
+       :Mem(p, r, c),my_stride(stride) {}
+
        GenericRowMajor(int r, int c)
        :Mem(r, c) {}
 
@@ -191,6 +194,6 @@
        }
 
        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());
+               return Matrix<-1, -1, Precision, Slice<SliceStride>::template 
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.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- test/mat_test2.cc   7 Feb 2009 13:32:24 -0000       1.2
+++ test/mat_test2.cc   7 Feb 2009 15:16:55 -0000       1.3
@@ -2,10 +2,8 @@
 using namespace TooN;
 using namespace std;
 
-void statictest()
+template<int R, int C, template<int,int,class> class B> void 
statictest(Matrix<R,C,double,B> m)
 {
-       Matrix<3,4> m;
-
        for(int i=0; i < 12; i++)
                (&m[0][0])[i] = i;
 
@@ -17,61 +15,77 @@
        cout << endl;
 
        cout << "Slice, from [1,1], size [2,3]:\n";
-       cout << m.slice<1,1,2,3>() << endl;
+       cout << m.template slice<1,1,2,3>() << endl;
 
        cout << "Accessing rows of a slice as vectors:\n";
        for(int i=0; i < 2; i++)
-               cout << "...  " << m.slice<1,1,2,3>()[i] << "...\n";
+               cout << "...  " << m.template slice<1,1,2,3>()[i] << "...\n";
        cout << endl;
 
 
 
        cout << "Slice, of the above slice from [0,0], size [2,1]:\n";
-       cout << m.slice<1,1,2,3>().slice<0,0,2,1>() << endl;
+       cout << m.template slice<1,1,2,3>().template slice<0,0,2,1>() << endl;
 
        cout << "Accessing rows of a slice of a slice as vectors:\n";
        for(int i=0; i < 2; i++)
-               cout << "...  " << m.slice<1,1,2,3>().slice<0,0,2,1>()[i] << 
"...\n";
+               cout << "...  " << m.template slice<1,1,2,3>().template 
slice<0,0,2,1>()[i] << "...\n";
        cout << endl;
 }
 
-void dynamictest()
+template<int R, int C, template<int,int,class> class B> void 
staticdynamictest(Matrix<R,C,double,B> m)
 {
-       Matrix<> m(3,4);
        for(int i=0; i < 12; i++)
                (&m[0][0])[i] = i;
 
        cout << m << endl;
 
-       cout << "Accessing rows as vectors:\n";
-       for(int i=0; i < 3; i++)
-               cout << "...  " << m[i] << "...\n";
+       cout << "Dynamic slice, from [1,1], size [2,3]:\n";
+       cout << m.slice(1,1,2,3) << endl;
+
+       cout << "Accessing rows of a slice as vectors:\n";
+       for(int i=0; i < 2; i++)
+               cout << "...  " << m.slice(1,1,2,3)[i] << "...\n";
        cout << endl;
 
-       cout << "Slice, from [1,1], size [2,3]:\n";
-       cout << m.slice<1,1,2,3>() << endl;
 
-       cout << "Accessing rows of a slice as vectors:\n";
+       cout << "Static slice, of the above slice from [0,0], size [2,1]:\n";
+       cout << m.slice(1,1,2,3).template slice<0,0,2,1>() << endl;
+
+       cout << "Accessing rows of a slice of a slice as vectors:\n";
        for(int i=0; i < 2; i++)
-               cout << "...  " << m.slice<1,1,2,3>()[i] << "...\n";
+               cout << "...  " << m.slice(1,1,2,3).template 
slice<0,0,2,1>()[i] << "...\n";
        cout << endl;
 
 
+       cout << "Dynamic slice, of the above slice from [0,0], size [2,1]:\n";
+       cout << m.slice(1,1,2,3).slice(0,0,2,1) << endl;
 
-       cout << "Slice, of the above slice from [0,0], size [2,1]:\n";
-       cout << m.slice<1,1,2,3>().slice<0,0,2,1>() << endl;
+       cout << "Accessing rows of a slice of a slice as vectors:\n";
+       for(int i=0; i < 2; i++)
+               cout << "...  " << m.slice(1,1,2,3).slice(0,0,2,1)[i] << 
"...\n";
+       cout << endl;
+
+       cout << "Dynamic slice, of static version of the above slice from 
[0,0], size [2,1]:\n";
+       cout << m.template slice<1,1,2,3>().slice(0,0,2,1) << endl;
 
        cout << "Accessing rows of a slice of a slice as vectors:\n";
        for(int i=0; i < 2; i++)
-               cout << "...  " << m.slice<1,1,2,3>().slice<0,0,2,1>()[i] << 
"...\n";
+               cout << "...  " << m.template 
slice<1,1,2,3>().slice(0,0,2,1)[i] << "...\n";
        cout << endl;
 }
 
 int main()
 {
        cout << "-------------- STATIC MATRIX STATIC SLICE\n";
-       statictest();
+       statictest(Matrix<3,4>());
 
        cout << "-------------- DYNAMIC MATRIX STATIC SLICE\n";
-       dynamictest();
+       statictest(Matrix<>(3,4));
+
+       cout << "-------------- STATIC MATRIX MIXED SLICE\n";
+       staticdynamictest(Matrix<3,4>());
+
+       cout << "-------------- DYNAMIC MATRIX MIXED SLICE\n";
+       staticdynamictest(Matrix<>(3,4));
 }




reply via email to

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