[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Toon-members] TooN util.h
From: |
Ethan Eade |
Subject: |
[Toon-members] TooN util.h |
Date: |
Mon, 15 Jan 2007 18:29:06 +0000 |
CVSROOT: /cvsroot/toon
Module name: TooN
Changes by: Ethan Eade <ethaneade> 07/01/15 18:29:06
Modified files:
. : util.h
Log message:
Some genericizing.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/TooN/util.h?cvsroot=toon&r1=1.3&r2=1.4
Patches:
Index: util.h
===================================================================
RCS file: /cvsroot/toon/TooN/util.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- util.h 3 Jul 2006 10:03:31 -0000 1.3
+++ util.h 15 Jan 2007 18:29:05 -0000 1.4
@@ -9,11 +9,15 @@
template <bool Cond> struct Assert;
template <> struct Assert<true> {};
- template <int B, int E> struct Dot {
+ template <int B, int E, bool Valid=(B<=E)> struct Dot {
+ template <class V1, class V2> static inline double eval(const V1&
v1, const V2& v2) { return 0; }
+ };
+
+ template <int B, int E> struct Dot<B,E,true> {
template <class V1, class V2> static inline double eval(const V1&
v1, const V2& v2) { return v1[B]* v2[B] + Dot<B+1,E>::eval(v1,v2); }
};
- template <int N> struct Dot<N,N> {
+ template <int N> struct Dot<N,N,true> {
template <class V1, class V2> static inline double eval(const V1&
v1, const V2& v2) { return v1[N]*v2[N]; }
};
@@ -59,21 +63,28 @@
#endif
template <int B, int Col=0> struct MatrixProductRow {
- template <class M1, class M2, class V> static inline void
eval(const M1& a, const M2& b, V& v, int row) {
- v[Col] = a[row] * b[Col];
- MatrixProductRow<B,Col+1>::eval(a,b,v, row);
+ template <class F, class M1, class M2, class V> static inline void
eval(const M1& a, const M2& b, V& v, int row) {
+ F::eval(v[Col], a[row] * b[Col]);
+ MatrixProductRow<B,Col+1>::template eval<F>(a,b,v, row);
}
};
template <int B> struct MatrixProductRow<B,B> {
- template <class M1, class M2, class V> static inline void
eval(const M1& a, const M2& b, V& v, int row) {
- v[B] = a[row] * b[B];
+ template <class F, class M1, class M2, class V> static inline void
eval(const M1& a, const M2& b, V& v, int row) {
+ F::template eval(v[B], a[row] * b[B]);
}
};
+ struct Assign { template <class LHS, class RHS> static inline void
eval(LHS& lhs, const RHS& rhs) { lhs = rhs; } };
+ struct PlusEquals { template <class LHS, class RHS> static inline void
eval(LHS& lhs, const RHS& rhs) { lhs += rhs; } };
+ struct MinusEquals { template <class LHS, class RHS> static inline void
eval(LHS& lhs, const RHS& rhs) { lhs -= rhs; } };
- template <int A, int N, int B, class M1, class M2, class M3> inline
void matrix_multiply(const M1& a, const M2& b, M3& m) {
+ template <class F, int A, int N, int B, class M1, class M2, class M3>
inline void matrix_multiply(const M1& a, const M2& b, M3& m) {
for (int i=0; i<m.num_rows(); i++)
- MatrixProductRow<B-1>::eval(a,b.T(),m[i],i);
+ MatrixProductRow<B-1>::template eval<F>(a,b.T(),m[i],i);
+ }
+
+ template <int A, int N, int B, class M1, class M2, class M3> inline
void matrix_multiply(const M1& a, const M2& b, M3& m) {
+ matrix_multiply<Assign,A,N,B,M1,M2,M3>(a,b,m);
}
}
- [Toon-members] TooN util.h,
Ethan Eade <=