toon-members
[Top][All Lists]
Advanced

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

[Toon-members] TooN TooN.h internal/mbase.hh test/test_foreign...


From: Edward Rosten
Subject: [Toon-members] TooN TooN.h internal/mbase.hh test/test_foreign...
Date: Thu, 26 Mar 2009 15:13:17 +0000

CVSROOT:        /cvsroot/toon
Module name:    TooN
Changes by:     Edward Rosten <edrosten>        09/03/26 15:13:17

Modified files:
        .              : TooN.h 
        internal       : mbase.hh 
        test           : test_foreign.cc 
Added files:
        internal       : foreign_matrix.hh 

Log message:
        New interface for wrapping foreign data, eg:
        
        double data[]={1, 2, 3, 4};
        Wrap<Dynamic,2>::wrap(data, 1)
        
        Works for wrapping contiguous matrices with any mixture of static and 
dynamic.
        It will only compile with the correct, unambiguous arguments.
        
        More wrappings to be added later...

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/TooN/TooN.h?cvsroot=toon&r1=1.27&r2=1.28
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/mbase.hh?cvsroot=toon&r1=1.22&r2=1.23
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/foreign_matrix.hh?cvsroot=toon&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/TooN/test/test_foreign.cc?cvsroot=toon&r1=1.2&r2=1.3

Patches:
Index: TooN.h
===================================================================
RCS file: /cvsroot/toon/TooN/TooN.h,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -b -r1.27 -r1.28
--- TooN.h      26 Mar 2009 14:31:43 -0000      1.27
+++ TooN.h      26 Mar 2009 15:13:16 -0000      1.28
@@ -70,6 +70,8 @@
        template<typename T> class Operator;
        template<typename T> class SliceSpec: public T{};
 
+       static const int Dynamic = -1;
+
        #include <TooN/internal/allocator.hh>
 
        #include <TooN/internal/size_mismatch.hh>
@@ -81,6 +83,7 @@
        
        #include <TooN/internal/mbase.hh>
        #include <TooN/internal/matrix.hh>
+       #include <TooN/internal/foreign_matrix.hh>
 
        #include <TooN/internal/make_vector.hh>
        #include <TooN/internal/operators.hh>

Index: internal/mbase.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/mbase.hh,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- internal/mbase.hh   26 Mar 2009 14:31:47 -0000      1.22
+++ internal/mbase.hh   26 Mar 2009 15:13:17 -0000      1.23
@@ -205,74 +205,4 @@
        };
 };
 
-////////////////////////////////////////////////////////////////////////////////
-//
-// Helper classes for matrices constructed as references to foreign data
-//
-
-namespace Reference
-{
-
-       struct RowMajor
-       {
-               template<int Rows, int Cols, class Precision> struct Layout: 
public Internal::GenericMBase<Rows, Cols, Precision, (Rows==-1?-2:Rows), 1, 
Internal::MatrixSlice<Rows, Cols, Precision> >
-               {
-                       template<class T> Layout(Precision* p, SliceSpec<T> 
spec)
-                       :Internal::GenericMBase<Rows, Cols, Precision, 
(Rows==-1?-2:Rows), 1, Internal::MatrixSlice<Rows, Cols, Precision> >(p, spec)
-                       {
-                       }
-               };
-       };
-/*
-       struct ColMajor
-       {
-               template<int Rows, int Cols, class Precision> struct Layout: 
public Internal::GenericMBase<Rows, Cols, Precision, 1, (Rows==-1?-2:Rows), 
Internal::MatrixSlice<Rows, Cols, Precision> >
-               {
-                       //Size fixed. Only data required.
-                       Layout(Precision* p)
-                       :Internal::GenericMBase<Rows, Cols, Precision, 1, 
(Rows==-1?-2:Rows), Internal::MatrixSlice<Rows, Cols, Precision> >(p)
-                       {
-                       }
-
-                       //Size dynamic: size and data needed.
-                       Layout(Precision* p, int rows, int cols)
-                       :Internal::GenericMBase<Rows, Cols, Precision, 1, (Rows 
== -1 ? -2 : Rows), Internal::MatrixAlloc<Rows, Cols, Precision> >(p, rows, 
cols, Internal::SpecifySize())
-                       {}
-               };
-       };
-
-
-       template<int Stride=-1> struct ColMajorStride
-       {
-               template<int Rows, int Cols, class Precision> struct Layout: 
public Internal::GenericMBase<Rows, Cols, Precision, 1, Stride, 
Internal::MatrixSlice<Rows, Cols, Precision> >
-               {
-                       
-                       //Size and stride fixed. Only data required.
-                       Layout(Precision* p)
-                       :Internal::GenericMBase<Rows, Cols, Precision, 1, 
Stride, Internal::MatrixSlice<Rows, Cols, Precision> >(p)
-                       {
-                       }
-
-                       //Size fixed. Data and stride required.
-                       Layout(Precision* p, int stride)
-                       :Internal::GenericMBase<Rows, Cols, Precision, 1, 
Stride, Internal::MatrixSlice<Rows, Cols, Precision> >(p, 1, stride, 
Internal::SpecifySize())
-                       {
-                       }
-
-                       //Stride fixed. Data and size required.
-                       Layout(Precision* p, int rows, int cols)
-                       :Internal::GenericMBase<Rows, Cols, Precision, 1, 
Stride, Internal::MatrixAlloc<Rows, Cols, Precision> >(p, rows, cols, 
Internal::SpecifySize())
-                       {}
-
-                       //Dynamic: Stride,  data and size required.
-                       Layout(Precision* p, int rows, int cols, int stride)
-                       :Internal::GenericMBase<Rows, Cols, Precision, 1, 
Stride, Internal::MatrixAlloc<Rows, Cols, Precision> >(p, rows, cols, 1, stride)
-                       {}
-               };
-       };*/
-}
-
-
-
-
 

Index: test/test_foreign.cc
===================================================================
RCS file: /cvsroot/toon/TooN/test/test_foreign.cc,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- test/test_foreign.cc        26 Mar 2009 14:31:47 -0000      1.2
+++ test/test_foreign.cc        26 Mar 2009 15:13:17 -0000      1.3
@@ -8,16 +8,12 @@
 {
        double data[]={1, 2, 3, 4};
 
-       SliceSpec<Internal::Spec_____> spec;
-
        Matrix<2> m = Identity;
 
        cout << m << endl;
 
-       Matrix<2, 2, double, Reference::RowMajor> n(data, spec);
-
-       cout << n << endl;
+       cout << Wrap<-1,2>::wrap(data, 1) << endl;
 
-       cout << m + n;
+       cout << m + Wrap<-1,2>::wrap(data,2);
 
 };

Index: internal/foreign_matrix.hh
===================================================================
RCS file: internal/foreign_matrix.hh
diff -N internal/foreign_matrix.hh
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ internal/foreign_matrix.hh  26 Mar 2009 15:13:16 -0000      1.1
@@ -0,0 +1,76 @@
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// Helper classes for matrices constructed as references to foreign data
+//
+
+namespace Reference
+{
+
+       struct RowMajor
+       {
+               template<int Rows, int Cols, class Precision> struct Layout: 
public Internal::GenericMBase<Rows, Cols, Precision, (Rows==-1?-2:Rows), 1, 
Internal::MatrixSlice<Rows, Cols, Precision> >
+               {
+                       template<class T> Layout(Precision* p, SliceSpec<T> 
spec)
+                       :Internal::GenericMBase<Rows, Cols, Precision, 
(Rows==-1?-2:Rows), 1, Internal::MatrixSlice<Rows, Cols, Precision> >(p, spec)
+                       {
+                       }
+               };
+       };
+
+       struct ColMajor
+       {
+               template<int Rows, int Cols, class Precision> struct Layout: 
public Internal::GenericMBase<Rows, Cols, Precision, 1, (Rows==-1?-2:Rows), 
Internal::MatrixSlice<Rows, Cols, Precision> >
+               {
+                       template<class T> Layout(Precision* p, SliceSpec<T> 
spec)
+                       :Internal::GenericMBase<Rows, Cols, Precision, 1, 
(Rows==-1?-2:Rows), Internal::MatrixSlice<Rows, Cols, Precision> >(p, spec)
+                       {
+                       }
+               };
+       };
+}
+
+
+template<int R, int C, typename Precision=double, class 
Type=Reference::RowMajor> struct Wrap
+{
+       static Matrix<R, C, Precision, Type> wrap(Precision* p)
+       {
+               SliceSpec<Internal::Spec_____> s;
+               return Matrix<R, C, Precision, Type>(p, s);
+       }
+};
+
+
+template<int R, typename Precision, class Type> struct Wrap<R, Dynamic, 
Precision, Type>
+{
+       static Matrix<R, Dynamic, Precision, Type> wrap(Precision* p, int cols)
+       {
+               SliceSpec<Internal::Spec__C__> s;
+               s.c = cols;
+               return Matrix<R, Dynamic, Precision, Type>(p, s);
+       }
+};
+
+
+template<int C, typename Precision, class Type> struct Wrap<Dynamic, C, 
Precision, Type>
+{
+       static Matrix<Dynamic, C, Precision, Type> wrap(Precision* p, int rows)
+       {
+               SliceSpec<Internal::Spec_R___> s;
+               s.r = rows;
+               return Matrix<Dynamic, C, Precision, Type>(p, s);
+       }
+};
+
+
+template<typename Precision, class Type> struct Wrap<Dynamic, Dynamic, 
Precision, Type>
+{
+       static Matrix<Dynamic, Dynamic, Precision, Type> wrap(Precision* p, int 
rows, int cols)
+       {
+               SliceSpec<Internal::Spec_RC__> s;
+               s.r = rows;
+               s.c = cols;
+               return Matrix<Dynamic, Dynamic, Precision, Type>(p, s);
+       }
+};
+




reply via email to

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