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
17 #include "virtual-methods.hh"
21 base class for interface with matrix storageclasses. There are no
22 iterators for matrixclasses, since matrices are (like arrays)
23 explicitly int-indexed.
25 Iteration is provided by *_next, *_ok, which update and check both
26 index variables simultaneously.
29 determine type of product matrix.
32 class Matrix_storage {
37 virtual void OK() const=0;
40 virtual int rows() const = 0;
43 virtual int cols() const = 0;
46 virtual int dim() const =0;
48 /** set the size. contents lost.
52 virtual void set_size (int rows, int cols) ;
55 /**set the size to square dimen. contents lost
59 virtual void set_size (int i) ;
62 keep contents. If enlarged contents unspecified
68 virtual void resize (int rows, int cols) = 0;
71 set the size to square dimen. contents kept
72 Keep contents. If enlarged contents are unspecified
77 virtual void resize (int i) = 0;
83 Generate an errormessage, if this happens
84 in the 0-part of a sparse matrix.
87 virtual Real& elem (int i,int j) = 0;
89 /// access a element, no modify
90 virtual Real elem (int i, int j) const = 0;
92 virtual Array<Real> row (int i) const ;
93 virtual Array<Real> column (int j) const;
97 add a row to the matrix before row k. Contents
98 of added row are unspecified
102 virtual void insert_row (int k)=0;
106 delete a row from this matrix.
111 virtual void delete_row (int k)=0;
112 virtual void delete_column (int k)=0;
113 virtual ~Matrix_storage() { }
114 virtual Matrix_storage *clone() const=0;
119 at end of matrix?. when doing loop
126 virtual bool mult_ok (int i, int j) const=0;
129 walk through matrix (regular multiply).
130 get next j for row i, or get next row i and reset j.
131 this will make sparse matrix implementation easy.
136 virtual void mult_next (int &i, int &j) const = 0;
139 valid matrix entry. return false if at end of row
141 virtual bool trans_ok (int i, int j) const=0;
144 walk through matrix (transposed multiply).
145 Get next i (for column j)
151 virtual void trans_next (int &i, int &j) const = 0;
153 /// generate a "Full_storage" matrix
154 static Matrix_storage *get_full (int n, int m);
155 static void set_band (Matrix_storage*&, int band);
156 static void set_full (Matrix_storage*&);
157 virtual bool try_right_multiply (Matrix_storage *dest,
158 const Matrix_storage *fact) const ;
162 DECLARE_MY_RUNTIME_TYPEINFO;
165 static Matrix_storage* get_product_result (Matrix_storage *left,
166 Matrix_storage *right);
169 static void set_addition_result (
170 Matrix_storage *&dat, Matrix_storage *right);
171 static void set_product_result (
172 Matrix_storage*&dest, Matrix_storage*left, Matrix_storage*right);
175 #endif // MATRIX_STORAGE_HH