[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Toon-members] TooN helpers.h internal/allocator.hh internal/m...
From: |
Tom Drummond |
Subject: |
[Toon-members] TooN helpers.h internal/allocator.hh internal/m... |
Date: |
Tue, 31 Mar 2009 04:25:55 +0000 |
CVSROOT: /cvsroot/toon
Module name: TooN
Changes by: Tom Drummond <twd20> 09/03/31 04:25:55
Modified files:
. : helpers.h
internal : allocator.hh matrix.hh mbase.hh
Log message:
matrices switched to new 0ary operators for Zero and Identity
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/TooN/helpers.h?cvsroot=toon&r1=1.37&r2=1.38
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/allocator.hh?cvsroot=toon&r1=1.22&r2=1.23
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/matrix.hh?cvsroot=toon&r1=1.21&r2=1.22
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/mbase.hh?cvsroot=toon&r1=1.23&r2=1.24
Patches:
Index: helpers.h
===================================================================
RCS file: /cvsroot/toon/TooN/helpers.h,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -b -r1.37 -r1.38
--- helpers.h 30 Mar 2009 23:05:22 -0000 1.37
+++ helpers.h 31 Mar 2009 04:25:54 -0000 1.38
@@ -47,39 +47,11 @@
namespace Internal{
- struct Zero {
- template<int R, int C, class P, class B>
- static void eval(Matrix<R, C, P, B>& m) {
- for(int r=0; r < m.num_rows(); r++) {
- for(int c=0; c < m.num_rows(); c++) {
- m[r][c] = 0;
- }
- }
- }
-
- template<int Size, class Precision, class Base>
- static void eval(Vector<Size, Precision, Base>&
v) {
- for(int i=0; i < v.size(); i++) {
- v[i]= 0;
- }
- }
- };
-
- struct Identity {
- template<int R, int C, class P, class B> static void
eval(Matrix<R, C, P, B>& m) {
- SizeMismatch<R, C>::test(m.num_rows(),
m.num_cols());
-
- for(int r=0; r < m.num_rows(); r++) {
- for(int c=0; c < m.num_rows(); c++) {
- m[r][c] = 0;
- }
- }
-
- for(int i=0; i < m.num_rows(); i++) {
- m[i][i] = 1;
- }
- }
- };
+ struct Zero;
+ struct SizedZero;
+ struct RCZero;
+ struct Identity;
+ struct SizedIdentity;
struct Copy
{
@@ -90,15 +62,41 @@
m[r][c] = *data++;
}
};
+ }
+
+
+ template<> struct Operator<Internal::RCZero> {
+ Operator(int r, int c) : my_rows(r), my_cols(c) {}
- class SizedZero;
+ const int my_rows;
+ const int my_cols;
+
+ int num_rows() const {return my_rows;}
+ int num_cols() const {return my_cols;}
+
+ template<int R, int C, class P, class B>
+ void eval(Matrix<R,C,P,B>& m) const {
+ for(int r=0; r<m.num_rows(); r++){
+ for(int c=0; c<m.num_cols(); c++){
+ m(r,c)=0;
+ }
+ }
}
+ };
template<> struct Operator<Internal::SizedZero> {
- int my_size;
- Operator(int s): my_size(s) {}
+
+ // no idea why this doesn't indent properly
+ Operator(int s) : my_size(s) {}
+
+ const int my_size;
+
+
int size() const {return my_size;}
+ int num_rows() const {return my_size;}
+ int num_cols() 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++) {
@@ -106,11 +104,19 @@
}
}
+ template<int R, int C, class P, class B>
+ void eval(Matrix<R,C,P,B>& m) const {
+ for(int r=0; r<m.num_rows(); r++){
+ for(int c=0; c<m.num_cols(); c++){
+ m(r,c)=0;
+ }
+ }
+ }
+
};
- template<> class Operator<Internal::Zero> {
- public:
+ template<> struct Operator<Internal::Zero> {
template<int Size, class Precision, class Base>
void eval(Vector<Size, Precision, Base>& v) const {
for(int i=0; i < v.size(); i++) {
@@ -118,10 +124,72 @@
}
}
+ template<int R, int C, class P, class B>
+ void eval(Matrix<R,C,P,B>& m) const {
+ for(int r=0; r<m.num_rows(); r++){
+ for(int c=0; c<m.num_cols(); c++){
+ m(r,c)=0;
+ }
+ }
+ }
+
Operator<Internal::SizedZero> operator()(int s){
return Operator<Internal::SizedZero>(s);
}
+ Operator<Internal::RCZero> operator()(int r, int c){
+ return Operator<Internal::RCZero>(r,c);
+ }
+
+ };
+
+ template<> struct Operator<Internal::SizedIdentity> {
+ // no idea why this doesn't indent properly
+ Operator(int s) : my_size(s) {}
+
+ const int my_size;
+
+ int num_rows() const {return my_size;}
+ int num_cols() const {return my_size;}
+
+ template<int R, int C, class P, class B>
+ void eval(Matrix<R,C,P,B>& m) const {
+ SizeMismatch<R, C>::test(m.num_rows(), m.num_cols());
+
+ for(int r=0; r<m.num_rows(); r++){
+ for(int c=0; c<m.num_cols(); c++){
+ m(r,c)=0;
+ }
+ }
+
+ for(int r=0; r < m.num_rows(); r++) {
+ m(r,r) = 1;
+ }
+ }
+ };
+
+
+
+ template<> struct Operator<Internal::Identity> {
+
+ template<int R, int C, class P, class B>
+ void eval(Matrix<R,C,P,B>& m) const {
+ SizeMismatch<R, C>::test(m.num_rows(), m.num_cols());
+
+ for(int r=0; r<m.num_rows(); r++){
+ for(int c=0; c<m.num_cols(); c++){
+ m(r,c)=0;
+ }
+ }
+
+ for(int r=0; r < m.num_rows(); r++) {
+ m(r,r) = 1;
+ }
+ }
+
+ Operator<Internal::SizedIdentity> operator()(int s){
+ return Operator<Internal::SizedIdentity>(s);
+ }
};
Index: internal/allocator.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/allocator.hh,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- internal/allocator.hh 31 Mar 2009 03:42:47 -0000 1.22
+++ internal/allocator.hh 31 Mar 2009 04:25:54 -0000 1.23
@@ -324,6 +324,12 @@
RowStrideHolder()
{}
+
+ template<class Op>
+ RowStrideHolder(const Operator<Op>& op)
+ : StrideHolder<S>(op)
+ {}
+
};
@@ -337,6 +343,11 @@
ColStrideHolder()
{}
+
+ template<class Op>
+ ColStrideHolder(const Operator<Op>& op)
+ : StrideHolder<S>(op)
+ {}
};
Index: internal/matrix.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/matrix.hh,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -b -r1.21 -r1.22
--- internal/matrix.hh 27 Mar 2009 15:42:46 -0000 1.21
+++ internal/matrix.hh 31 Mar 2009 04:25:54 -0000 1.22
@@ -33,10 +33,10 @@
//See vector.hh and allocator.hh for details about why the
//copy constructor should be default.
template <class Op>
- inline Matrix(const Operator<Op> &, int rows = Rows, int cols = Cols )
- :Layout::template Layout<Rows,Cols,Precision>(rows, cols)
+ inline Matrix(const Operator<Op>& op)
+ :Layout::template Layout<Rows,Cols,Precision>(op)
{
- Op::eval(*this);
+ op.eval(*this);
}
// constructors to allow return value optimisations
// construction from 1-ary operator
@@ -77,9 +77,9 @@
}
// operator = 0-ary operator
- template<class Op> inline Matrix& operator= (const Operator<Op>&)
+ template<class Op> inline Matrix& operator= (const Operator<Op>& op)
{
- Op::eval(*this);
+ op.eval(*this);
}
// operator =
Index: internal/mbase.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/mbase.hh,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -b -r1.23 -r1.24
--- internal/mbase.hh 26 Mar 2009 15:13:17 -0000 1.23
+++ internal/mbase.hh 31 Mar 2009 04:25:55 -0000 1.24
@@ -81,6 +81,13 @@
GenericMBase(int r, int c)
:Mem(r, c) {}
+ template<class Op>
+ GenericMBase(const Operator<Op>& op)
+ : Mem(op),
+ RowStrideHolder<RowStride>(op),
+ ColStrideHolder<ColStride>(op)
+ {}
+
//Unpack slice specifications in to specific constructors
//These slice specifications are not allowed to ignore superfluous data.
GenericMBase(Precision* p, const Spec_____& s):Mem(p
)
{}
@@ -188,6 +195,12 @@
Layout(int rows, int cols)
:Internal::GenericMBase<Rows, Cols, Precision, (Cols == -1 ? -2
: Cols), 1, Internal::MatrixAlloc<Rows, Cols, Precision> >(rows, cols)
{}
+
+ template<class Op>
+ Layout(const Operator<Op>& op)
+ :Internal::GenericMBase<Rows, Cols, Precision, (Cols ==
-1 ? -2 : Cols), 1, Internal::MatrixAlloc<Rows, Cols, Precision> >(op)
+ {}
+
};
};
@@ -202,6 +215,12 @@
Layout(int rows, int cols)
:Internal::GenericMBase<Rows, Cols, Precision, 1, (Rows == -1 ?
-2 : Rows), Internal::MatrixAlloc<Rows, Cols, Precision> >(rows, cols)
{}
+
+ template<class Op>
+ Layout(const Operator<Op>& op)
+ :Internal::GenericMBase<Rows, Cols, Precision, 1, (Rows
== -1 ? -2 : Rows), Internal::MatrixAlloc<Rows, Cols, Precision> >(op)
+ {}
+
};
};
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Toon-members] TooN helpers.h internal/allocator.hh internal/m...,
Tom Drummond <=