toon-members
[Top][All Lists]
Advanced

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

[Toon-members] TooN helpers.h internal/allocator.hh internal/o...


From: Tom Drummond
Subject: [Toon-members] TooN helpers.h internal/allocator.hh internal/o...
Date: Mon, 30 Mar 2009 20:01:32 +0000

CVSROOT:        /cvsroot/toon
Module name:    TooN
Changes by:     Tom Drummond <twd20>    09/03/30 20:01:32

Modified files:
        .              : helpers.h 
        internal       : allocator.hh operators.hh vbase.hh vector.hh 
        test           : test3.cc 

Log message:
        began work on moving everything to 0-ary constructors for Vector
        Zero still works
        Vector+Vector now uses 0-ary

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/TooN/helpers.h?cvsroot=toon&r1=1.33&r2=1.34
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/allocator.hh?cvsroot=toon&r1=1.20&r2=1.21
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/operators.hh?cvsroot=toon&r1=1.23&r2=1.24
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/vbase.hh?cvsroot=toon&r1=1.20&r2=1.21
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/vector.hh?cvsroot=toon&r1=1.30&r2=1.31
http://cvs.savannah.gnu.org/viewcvs/TooN/test/test3.cc?cvsroot=toon&r1=1.5&r2=1.6

Patches:
Index: helpers.h
===================================================================
RCS file: /cvsroot/toon/TooN/helpers.h,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -b -r1.33 -r1.34
--- helpers.h   25 Mar 2009 22:33:21 -0000      1.33
+++ helpers.h   30 Mar 2009 20:01:31 -0000      1.34
@@ -93,6 +93,18 @@
 
 }
 
+
+template<> class Operator<Internal::Zero> {
+ public:
+       template<int Size, class Precision, class Base>
+               void eval(Vector<Size, Precision, Base>& v) const {
+               for(int i=0; i < v.size(); i++) {
+                       v[i]= 0;
+               }
+       }
+ };
+
+
 static Operator<Internal::Zero> Zero;
 static Operator<Internal::Identity> Identity;
 

Index: internal/allocator.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/allocator.hh,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -b -r1.20 -r1.21
--- internal/allocator.hh       26 Mar 2009 14:31:45 -0000      1.20
+++ internal/allocator.hh       30 Mar 2009 20:01:32 -0000      1.21
@@ -45,14 +45,14 @@
 {
 };
 
-template<int Size, class Precision> struct VectorAlloc: public 
StaticSizedAllocator<Size, Precision>{
+template<int Size, class Precision> struct VectorAlloc : public 
StaticSizedAllocator<Size, Precision> {
        
-       VectorAlloc()
-       { }
+       VectorAlloc() { }
 
-       VectorAlloc(int /*s*/)
-       { }
+       VectorAlloc(int /*s*/) { }
 
+       template<class Op>
+       VectorAlloc(const Operator<Op>& op) {}
 
        int size() const {
                return Size;
@@ -74,6 +74,9 @@
        :my_data(new Precision[s]), my_size(s)
        { }
 
+       template <class Op>
+       VectorAlloc(const Operator<Op>& op) : my_data(new 
Precision[op.size()]), my_size(op.size()) {}
+
        int size() const {
                return my_size;
        }
@@ -99,6 +102,9 @@
 
        VectorSlice(Precision* p, int /*size*/)
        :my_data(p){}
+
+       template<class Op>
+       VectorSlice(const Operator<Op>& op) : my_data(op.data()) {}
 };
 
 template<class Precision> struct VectorSlice<-1, Precision>
@@ -110,6 +116,9 @@
        :my_data(d), my_size(s)
        { }
 
+       template<class Op>
+       VectorSlice(const Operator<Op>& op) : my_data(op.data()), 
my_size(op.size()) {}
+
        int size() const {
                return my_size;
        }
@@ -317,6 +326,9 @@
        StrideHolder(){}
        StrideHolder(int){}
 
+       template<class Op>
+       StrideHolder(const Operator<Op>& op) {}
+
        int stride() const{
                return s;
        }
@@ -331,6 +343,9 @@
        StrideHolder(int s, const Internal::NoIgnore&)
        :my_stride(s){}
 
+       template<class Op>
+       StrideHolder(const Operator<Op>& op) : my_stride(op.stride()) {}
+
        const int my_stride;
        int stride() const {
                return my_stride;

Index: internal/operators.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/operators.hh,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -b -r1.23 -r1.24
--- internal/operators.hh       26 Mar 2009 10:36:17 -0000      1.23
+++ internal/operators.hh       30 Mar 2009 20:01:32 -0000      1.24
@@ -17,6 +17,7 @@
        
        //Operator classes. These are evaluated in the constructor
        //of Vector = Vector+Vector, so make use of return value optimization.
+
        template<typename Precision, typename Op> struct Pairwise
        {
                template<int S, typename B, int S1, typename P1, typename B1, 
int S2, typename P2, typename B2> 
@@ -145,6 +146,32 @@
        template<> struct Sizer<-1, -1>    {static const int size=-1;};
 }
 
+
+template<typename Op,                           // the operation
+                int S1, typename P1, typename B1,      // lhs vector
+                int S2, typename P2, typename B2>      // rhs vector
+struct VPairwise;
+
+template<typename Op,                           // the operation
+                int S1, typename P1, typename B1,      // lhs vector
+                int S2, typename P2, typename B2>      // rhs vector
+struct Operator<VPairwise<Op, S1, P1, B1, S2, P2, B2> > {
+       const Vector<S1, P1, B1> & lhs;
+       const Vector<S2, P2, B2> & rhs;
+
+       Operator(const Vector<S1, P1, B1> & lhs_in, const Vector<S2, P2, B2> & 
rhs_in) : lhs(lhs_in), rhs(rhs_in) {}
+
+       template<int S0, typename P0, typename B0>
+       void eval(Vector<S0, P0, B0>& res) const
+       {
+               for(int i=0; i < res.size(); ++i)
+                       res[i] = Op::template op<P0,P1, P2>(lhs[i],rhs[i]);
+       }
+       int size() const {return lhs.size();}
+};
+
+
+
 
////////////////////////////////////////////////////////////////////////////////
 //
 // vector <op> vector
@@ -155,9 +182,11 @@
 template<int S1, int S2, typename P1, typename P2, typename B1, typename B2> 
 Vector<Internal::Sizer<S1,S2>::size, typename Internal::AddType<P1, P2>::type> 
operator+(const Vector<S1, P1, B1>& v1, const Vector<S2, P2, B2>& v2)
 {
-       typedef typename Internal::AddType<P1, P2>::type restype;
+       typedef typename Internal::AddType<P1, P2>::type P0;
        SizeMismatch<S1, S2>:: test(v1.size(),v2.size());
-       return Vector<Internal::Sizer<S1,S2>::size,restype>(v1, v2, v1.size(), 
Operator<Internal::Pairwise<restype, Internal::Add> >());
+       const int S0=Internal::Sizer<S1,S2>::size;
+       return 
Vector<S0,P0>(Operator<VPairwise<Internal::Add,S1,P1,B1,S2,P2,B2> >(v1,v2));
+       // return Vector<Internal::Sizer<S1,S2>::size,restype>(v1, v2, 
v1.size(), Operator<Internal::Pairwise<restype, Internal::Add> >());
 }
 
 // Addition Vector - Vector

Index: internal/vbase.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/vbase.hh,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -b -r1.20 -r1.21
--- internal/vbase.hh   30 Mar 2009 18:21:39 -0000      1.20
+++ internal/vbase.hh   30 Mar 2009 20:01:32 -0000      1.21
@@ -23,6 +23,10 @@
                Layout(Precision* d, int length, int stride)
                        :GenericVBase<Size, Precision, Stride, 
VectorSlice<Size, Precision> >(d, length, stride){
                }
+
+               template<class Op>
+               Layout(const Operator<Op>& op)
+                       :GenericVBase<Size, Precision, Stride, 
VectorSlice<Size, Precision> >(op) {}
        };
 
 };
@@ -44,6 +48,10 @@
                Layout(int s)
                        :GenericVBase<Size, Precision, 1, VectorAlloc<Size, 
Precision> >(s)
                {}
+
+               template<class Op>
+               Layout(const Operator<Op>& op)
+                       :GenericVBase<Size, Precision, 1, VectorAlloc<Size, 
Precision> >(op) {}
        };
 };
 
@@ -69,6 +77,9 @@
        :Mem(d, length),StrideHolder<Stride>(stride){
        }
 
+       template<class Op>
+       GenericVBase(const Operator<Op> & op) : Mem(op), 
StrideHolder<Stride>(op) {}
+
        using Mem::my_data;
        using Mem::size;
 

Index: internal/vector.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/vector.hh,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -b -r1.30 -r1.31
--- internal/vector.hh  30 Mar 2009 19:15:15 -0000      1.30
+++ internal/vector.hh  30 Mar 2009 20:01:32 -0000      1.31
@@ -16,9 +16,9 @@
        // construction from 0-ary operator
        template <class Op>
        inline Vector(const Operator<Op>& op)
-       //      : Base::template Layout<Size, Precision> (op)
+               : Base::template Layout<Size, Precision> (op)
        {
-               Op::eval(*this);
+               op.eval(*this);
        }
 
        // constructors to allow return value optimisations
@@ -53,8 +53,8 @@
 
        // assignment from a 0-ary operator
        template <class Op>
-       inline Vector & operator=(const Operator<Op>&){
-               Op::eval(*this);
+       inline Vector & operator=(const Operator<Op>& op){
+               op.eval(*this);
                return *this;
        }
 

Index: test/test3.cc
===================================================================
RCS file: /cvsroot/toon/TooN/test/test3.cc,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6




reply via email to

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