2 matrix-storage.hh -- declare Matrix_storage
4 source file of the Flower Library
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
10 #ifndef MATRIX_STORAGE_HH
11 #define MATRIX_STORAGE_HH
15 #include "virtual-methods.hh"
19 base class for interface with matrix storageclasses. There are no
20 iterators for matrixclasses, since matrices are (like arrays)
21 explicitly int-indexed.
23 Iteration is provided by *_next, *_ok, which update and check both
24 index variables simultaneously.
27 determine type of product matrix.
30 class Matrix_storage {
35 virtual void OK() const=0;
38 virtual int rows() const = 0;
41 virtual int cols() const = 0;
44 virtual int dim() const =0;
46 /** set the size. contents lost.
50 virtual void set_size(int rows, int cols) ;
53 /**set the size to square dimen. contents lost
57 virtual void set_size(int i) ;
60 keep contents. If enlarged contents unspecified
66 virtual void resize(int rows, int cols ) = 0;
69 set the size to square dimen. contents kept
70 Keep contents. If enlarged contents are unspecified
75 virtual void resize(int i) = 0;
81 Generate an errormessage, if this happens
82 in the 0-part of a sparse matrix.
85 virtual Real& elem(int i,int j) = 0;
87 /// access a element, no modify
88 virtual Real elem(int i, int j) const = 0;
90 virtual Array<Real> row(int i) const ;
91 virtual Array<Real> column(int j) const;
95 add a row to the matrix before row k. Contents
96 of added row are unspecified
100 virtual void insert_row(int k)=0;
104 delete a row from this matrix.
109 virtual void delete_row(int k)=0;
110 virtual void delete_column(int k)=0;
111 virtual ~Matrix_storage() { }
112 virtual Matrix_storage *clone()const=0;
117 at end of matrix?. when doing loop
124 virtual bool mult_ok(int i, int j) const=0;
127 walk through matrix (regular multiply).
128 get next j for row i, or get next row i and reset j.
129 this will make sparse matrix implementation easy.
134 virtual void mult_next(int &i, int &j) const = 0;
137 valid matrix entry. return false if at end of row
139 virtual bool trans_ok(int i, int j) const=0;
142 walk through matrix (transposed multiply).
143 Get next i (for column j)
149 virtual void trans_next(int &i, int &j) const = 0;
151 /// generate a "Full_storage" matrix
152 static Matrix_storage *get_full(int n, int m);
153 static void set_band(Matrix_storage*&, int band);
154 static void set_full(Matrix_storage*&);
155 virtual bool try_right_multiply(Matrix_storage *dest,
156 const Matrix_storage *fact)const ;
160 DECLARE_MY_RUNTIME_TYPEINFO;
163 static Matrix_storage* get_product_result(Matrix_storage *left,
164 Matrix_storage *right);
167 static void set_addition_result(
168 Matrix_storage *&dat, Matrix_storage *right);
169 static void set_product_result(
170 Matrix_storage*&dest, Matrix_storage*left, Matrix_storage*right);
173 #endif // MATRIX_STORAGE_HH