[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Toon-members] TooN helpers.h
From: |
Tom Drummond |
Subject: |
[Toon-members] TooN helpers.h |
Date: |
Mon, 30 Mar 2009 23:05:22 +0000 |
CVSROOT: /cvsroot/toon
Module name: TooN
Changes by: Tom Drummond <twd20> 09/03/30 23:05:22
Modified files:
. : helpers.h
Log message:
can give Zero a size so that it can be used to construct dynamic
vectors by:
int n;
Vector<> v=Zero(n);
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/TooN/helpers.h?cvsroot=toon&r1=1.36&r2=1.37
Patches:
Index: helpers.h
===================================================================
RCS file: /cvsroot/toon/TooN/helpers.h,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -b -r1.36 -r1.37
--- helpers.h 30 Mar 2009 22:52:11 -0000 1.36
+++ helpers.h 30 Mar 2009 23:05:22 -0000 1.37
@@ -26,26 +26,26 @@
namespace TooN {
-template<int Size, class Precision, class Base> void Fill(Vector<Size,
Precision, Base>& v, const Precision& p)
-{
+ template<int Size, class Precision, class Base> void Fill(Vector<Size,
Precision, Base>& v, const Precision& p)
+ {
for(int i=0; i < v.size(); i++)
v[i]= p;
-}
+ }
-template<int Rows, int Cols, class Precision, class Base> void
Fill(Matrix<Rows, Cols, Precision, Base>& m, const Precision& p)
-{
+ template<int Rows, int Cols, class Precision, class Base> void
Fill(Matrix<Rows, Cols, Precision, Base>& m, const Precision& p)
+ {
for(int i=0; i < m.num_rows(); i++)
for(int j=0; j < m.num_cols(); j++)
m[i][j] = p;
-}
+ }
-template<int Size, class Precision, class Base> inline Vector<Size, Precision>
unit(const Vector<Size, Precision, Base> & v)
-{
+ template<int Size, class Precision, class Base> inline Vector<Size,
Precision> unit(const Vector<Size, Precision, Base> & v)
+ {
using std::sqrt;
return v/sqrt(v*v);
-}
+ }
-namespace Internal{
+ namespace Internal{
struct Zero {
template<int R, int C, class P, class B>
@@ -91,10 +91,25 @@
}
};
-}
+ class SizedZero;
+ }
+
+ template<> struct Operator<Internal::SizedZero> {
+ int my_size;
+ Operator(int s): my_size(s) {}
+ int size() const {return my_size;}
+ 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;
+ }
+ }
-template<> class Operator<Internal::Zero> {
+ };
+
+
+ template<> class Operator<Internal::Zero> {
public:
template<int Size, class Precision, class Base>
void eval(Vector<Size, Precision, Base>& v) const {
@@ -102,11 +117,16 @@
v[i]= 0;
}
}
+
+ Operator<Internal::SizedZero> operator()(int s){
+ return Operator<Internal::SizedZero>(s);
+ }
+
};
-static Operator<Internal::Zero> Zero;
-static Operator<Internal::Identity> Identity;
+ static Operator<Internal::Zero> Zero;
+ static Operator<Internal::Identity> Identity;
}