[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Toon-members] TooN/internal allocator.hh
From: |
Edward Rosten |
Subject: |
[Toon-members] TooN/internal allocator.hh |
Date: |
Tue, 24 Feb 2009 17:47:51 +0000 |
CVSROOT: /cvsroot/toon
Module name: TooN
Changes by: Edward Rosten <edrosten> 09/02/24 17:47:51
Modified files:
internal : allocator.hh
Log message:
Half dynamic matrices. These follow the usual TooN convention that -1
is a
dynamic size. A 10 by static 6 matrix is declared as follows:
Matrix<-1,6> m(10,6);
Note, both arguments to the construtor are required, but the compiler
will
simply ignore the argument referring to the static dimension.
Very lightly tested.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/allocator.hh?cvsroot=toon&r1=1.13&r2=1.14
Patches:
Index: allocator.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/allocator.hh,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- allocator.hh 18 Feb 2009 18:48:17 -0000 1.13
+++ allocator.hh 24 Feb 2009 17:47:51 -0000 1.14
@@ -131,6 +131,65 @@
}
};
+
+template<int Rows, class Precision> struct MatrixAlloc<Rows, -1, Precision>
+{
+ const int my_cols;
+ Precision* const my_data;
+
+ MatrixAlloc(const MatrixAlloc& m)
+ :my_cols(m.my_cols),my_data(new Precision[Rows*my_cols]) {
+ const int size=Rows*my_cols;
+ for(int i=0; i < size; i++)
+ my_data[i] = m.my_data[i];
+ }
+
+ MatrixAlloc(int, int c)
+ :my_cols(c),my_data(new Precision[Rows*c]) {
+ }
+
+ ~MatrixAlloc() {
+ delete[] my_data;
+ }
+
+ int num_rows() const {
+ return Rows;
+ }
+
+ int num_cols() const {
+ return my_cols;
+ }
+};
+
+template<int Cols, class Precision> struct MatrixAlloc<-1, Cols, Precision>
+{
+ const int my_rows;
+ Precision* const my_data;
+
+ MatrixAlloc(const MatrixAlloc& m)
+ :my_rows(m.my_rows),my_data(new Precision[my_rows*Cols]) {
+ const int size=Cols*my_rows;
+ for(int i=0; i < size; i++)
+ my_data[i] = m.my_data[i];
+ }
+
+ MatrixAlloc(int r, int)
+ :my_rows(r),my_data(new Precision[r*Cols]) {
+ }
+
+ ~MatrixAlloc() {
+ delete[] my_data;
+ }
+
+ int num_rows() const {
+ return my_rows;
+ }
+
+ int num_cols() const {
+ return Cols;
+ }
+};
+
template<class Precision> struct MatrixAlloc<-1, -1, Precision>
{
const int my_rows;
@@ -182,6 +241,46 @@
:my_data(p){}
};
+
+
+template<int Rows, class Precision> struct MatrixSlice<Rows, -1, Precision>
+{
+ Precision* const my_data;
+ const int my_cols;
+
+ MatrixSlice(Precision* d, int r, int c)
+ :my_data(d),my_cols(c)
+ {
+ }
+
+ int num_rows() const {
+ return Rows;
+ }
+
+ int num_cols() const {
+ return my_cols;
+ }
+};
+
+template<int Cols, class Precision> struct MatrixSlice<-1, Cols, Precision>
+{
+ Precision* const my_data;
+ const int my_rows;
+
+ MatrixSlice(Precision* d, int r, int c)
+ :my_data(d),my_rows(r)
+ {
+ }
+
+ int num_rows() const {
+ return my_rows;
+ }
+
+ int num_cols() const {
+ return Cols;
+ }
+};
+
template<class Precision> struct MatrixSlice<-1, -1, Precision>
{
Precision* const my_data;