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/operators.h...


From: Edward Rosten
Subject: [Toon-members] TooN internal/allocator.hh internal/operators.h...
Date: Tue, 17 Feb 2009 13:40:32 +0000

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

Modified files:
        internal       : allocator.hh operators.hh vector.hh 
Added files:
        test           : test2.cc 

Log message:
        First operator seems to work. Vectors can now be added. Vector is 
responsible
        for passing size on to VBase.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/allocator.hh?cvsroot=toon&r1=1.10&r2=1.11
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/operators.hh?cvsroot=toon&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/vector.hh?cvsroot=toon&r1=1.9&r2=1.10
http://cvs.savannah.gnu.org/viewcvs/TooN/test/test2.cc?cvsroot=toon&rev=1.1

Patches:
Index: internal/allocator.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/allocator.hh,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- internal/allocator.hh       10 Feb 2009 12:19:54 -0000      1.10
+++ internal/allocator.hh       17 Feb 2009 13:40:31 -0000      1.11
@@ -37,6 +37,13 @@
 
 template<int Size, class Precision> struct VectorAlloc: public 
StaticSizedAllocator<Size, Precision>{
        
+       VectorAlloc()
+       { }
+
+       VectorAlloc(int /*s*/)
+       { }
+
+
        int size() const {
                return Size;
        }

Index: internal/operators.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/operators.hh,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- internal/operators.hh       7 Feb 2009 15:36:47 -0000       1.1
+++ internal/operators.hh       17 Feb 2009 13:40:32 -0000      1.2
@@ -4,6 +4,37 @@
 //                                       Operators
 
//////////////////////////////////////////////////////////////////////////////////////////////
 
+template<class Op> struct Operator{};
+
+namespace Internal{
+
+       template<typename Precision> struct Add
+       {
+               template<int S, typename B, int S1, typename B1, int S2, 
typename B2> 
+               static void eval(Vector<S, Precision, B>& res, const Vector<S1, 
Precision, B1>& v1, const Vector<S2, Precision, B2>& v2)
+               {
+                       SizeMismatch<S1, S2>:: test(v1.size(),v2.size());
+                       for(int i=0; i < res.size(); ++i)
+                               res[i] = v1[i] + v2[i];
+               }
+
+               template<int S1, typename B1, int S2, typename B2> 
+               static int size(const Vector<S1, Precision, B1>& v1, const 
Vector<S2, Precision, B2>& v2)
+               {
+                       SizeMismatch<S1, S2>:: test(v1.size(),v2.size());
+                       return v1.size();
+               }
+       };
+}
+
+
+// Addition Vector + Vector
+template<int Size, typename Precision, typename B1, typename B2> 
+Vector<Size, Precision> operator+(const Vector<Size, Precision, B1>& v1, const 
Vector<Size, Precision, B2>& v2)
+{
+       return Vector<Size, Precision>(v1, v2, Operator<Internal::Add<double> 
>());
+}
+
 
 // Dot product Vector * Vector
 template<int Size1, typename Precision1, typename Base1,

Index: internal/vector.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/vector.hh,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- internal/vector.hh  8 Feb 2009 19:18:58 -0000       1.9
+++ internal/vector.hh  17 Feb 2009 13:40:32 -0000      1.10
@@ -1,5 +1,4 @@
 //-*- c++ -*-
-
 template<int Size=-1, typename Precision=double, typename Base=VBase<Size, 
Precision> >
 class Vector : public Base {
 public:
@@ -16,14 +15,14 @@
   // constructors to allow return value optimisations
   // construction from 1-ary operator
   template <class T, class Op>
-  inline Vector(const T& arg, const Operator<Op>& op) : Base(arg,op) {
+  inline Vector(const T& arg, const Operator<Op>&) : Base(Op::size(arg)) {
     Op::eval(*this,arg);
   }
 
   // constructor from 2-ary operator
   template <class LHS, class RHS, class Op>
-  inline Vector(const LHS& lhs, const RHS& rhs, const Operator<Op>& op)
-    : Base(lhs,rhs,op) {
+  inline Vector(const LHS& lhs, const RHS& rhs, const Operator<Op>&)
+    : Base(Op::size(lhs, rhs)) {
     Op::eval(*this,lhs,rhs);
   }
 

Index: test/test2.cc
===================================================================
RCS file: test/test2.cc
diff -N test/test2.cc
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ test/test2.cc       17 Feb 2009 13:40:32 -0000      1.1
@@ -0,0 +1,15 @@
+#include <TooN/TooN.h>
+
+using namespace std;
+using namespace TooN;
+
+int main()
+{
+       Vector<4> v1 = makeVector(1, 2, 3, 4);
+       Vector<4> v2 = makeVector(5, 6, 7, 8);
+
+       cout << v1 + v2 << endl;
+
+
+}
+




reply via email to

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