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 13:32:24 +0000

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

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

Log message:
        Dynamic matrix working.
        
        test/mat_test2.cc compiles (static slices of dynamic matrices).

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

Patches:
Index: internal/allocator.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/allocator.hh,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- internal/allocator.hh       7 Feb 2009 12:17:52 -0000       1.3
+++ internal/allocator.hh       7 Feb 2009 13:32:24 -0000       1.4
@@ -100,11 +100,11 @@
        }
 
        int num_rows() const {
-               return num_rows;
+               return my_rows;
        }
 
        int num_cols() const {
-               return num_cols;
+               return my_cols;
        }
 };
 
@@ -141,11 +141,11 @@
        }
 
        int num_rows() const {
-               return num_rows;
+               return my_rows;
        }
 
        int num_cols() const {
-               return num_cols;
+               return my_cols;
        }
 };
 

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

Index: internal/mbase.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/mbase.hh,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- internal/mbase.hh   7 Feb 2009 12:17:53 -0000       1.4
+++ internal/mbase.hh   7 Feb 2009 13:32:24 -0000       1.5
@@ -133,10 +133,12 @@
 //
 template<int Rows, int Cols, class Precision, int Stride, class Mem> struct 
GenericRowMajor: public Mem
 {
+       //Slices can never have tied strides
+       static const int SliceStride = Stride == -2?-1: Stride;
 
        //This little hack returns the stride value if it exists,
        //or one of the implied strides if they exist.
-       int tied_stride(){ 
+       int tied_stride() const{ 
                //Only valid if stride is -2
                return num_cols();
        }
@@ -151,16 +153,16 @@
        GenericRowMajor(){}
 
        GenericRowMajor(Precision* p)
-       :Mem(p)
-       {}
+       :Mem(p) {}
 
        GenericRowMajor(Precision* p, int s)
-       :Mem(p),my_stride(s)
-       {}
+       :Mem(p),my_stride(s) {}
 
        GenericRowMajor(Precision* p, int r, int c)
-       :Mem(p, r, c)
-       {}
+       :Mem(p, r, c) {}
+
+       GenericRowMajor(int r, int c)
+       :Mem(r, c) {}
 
        using Mem::my_data;
        using Mem::num_cols;
@@ -181,16 +183,14 @@
        }
 
        template<int Rstart, int Cstart, int Rlength, int Clength>
-       Matrix<Rlength, Clength, Precision, Slice<Stride>::template RowMajor> 
slice()
+       Matrix<Rlength, Clength, Precision, Slice<SliceStride>::template 
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<Stride>::template RowMajor>(my_data+stride()*Rstart + Cstart, stride(), 
Slicing());
+               return Matrix<Rlength, Clength, Precision, 
Slice<SliceStride>::template RowMajor>(my_data+stride()*Rstart + Cstart, 
stride(), Slicing());
        }
 
-       Matrix<-1, -1, Precision, Slice<Stride>::template RowMajor > slice(int 
rs, int cs, int rl, int cl){
-               return Matrix<-1, -1, Precision, Slice<Stride>::template 
RowMajor >(my_data+stride()*rs +cs, rl, cl, stride());
+       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());
        }
-
-
 };

Index: test/mat_test2.cc
===================================================================
RCS file: /cvsroot/toon/TooN/test/mat_test2.cc,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- test/mat_test2.cc   7 Feb 2009 12:17:53 -0000       1.1
+++ test/mat_test2.cc   7 Feb 2009 13:32:24 -0000       1.2
@@ -2,7 +2,7 @@
 using namespace TooN;
 using namespace std;
 
-int main()
+void statictest()
 {
        Matrix<3,4> m;
 
@@ -34,3 +34,44 @@
                cout << "...  " << m.slice<1,1,2,3>().slice<0,0,2,1>()[i] << 
"...\n";
        cout << endl;
 }
+
+void dynamictest()
+{
+       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 << 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";
+       for(int i=0; i < 2; i++)
+               cout << "...  " << m.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 << "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;
+}
+
+int main()
+{
+       cout << "-------------- STATIC MATRIX STATIC SLICE\n";
+       statictest();
+
+       cout << "-------------- DYNAMIC MATRIX STATIC SLICE\n";
+       dynamictest();
+}




reply via email to

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