]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/matrix-storage.hh
5027b6f5558afa94d13ef9dfc00511d6017790cd
[lilypond.git] / flower / include / matrix-storage.hh
1 /*
2   matrix-storage.hh -- declare Matrix_storage
3
4   source file of the Flower Library
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9
10 #ifndef MATRIX_STORAGE_HH
11 #define MATRIX_STORAGE_HH
12
13 #include "varray.hh"
14 #include "real.hh"
15 #include "virtual-methods.hh"
16
17 /** 
18
19     base class for interface with matrix storageclasses.  There are no
20     iterators for matrixclasses, since matrices are (like arrays)
21     explicitly int-indexed.
22
23     Iteration is provided by *_next, *_ok, which update and check both
24     index variables simultaneously.
25
26     TODO
27     determine type of product matrix.
28
29 */
30 class Matrix_storage {
31     
32
33 public:
34     /// check invariants
35     virtual void OK() const=0;
36     
37     /// height of matrix
38     virtual int rows() const = 0;
39
40     /// width of matrix
41     virtual int cols() const = 0;
42
43     /// size if square
44     virtual int dim() const =0;
45       
46     /**  set the size. contents lost.       
47       PRE
48       i >=0, j>=0
49     */
50     virtual void set_size (int rows, int cols) ;
51
52  
53     /**set the size to square dimen. contents lost
54       PRE
55       i>=0
56     */
57     virtual void set_size (int i) ;
58      /**set the size to i.
59
60       keep contents. If enlarged contents unspecified
61         
62       PRE
63       i>=0, j>=0
64     
65     */
66     virtual void resize (int rows, int cols) = 0;
67  
68   /**    
69     set the size to square dimen. contents kept
70     Keep contents. If enlarged contents are unspecified
71     
72     PRE
73     i>=0  
74     */
75     virtual void resize (int i) = 0;
76   
77     
78     /**
79     access an element.
80
81     Generate an errormessage, if this happens
82     in the 0-part of a sparse matrix.
83     */
84
85     virtual Real& elem (int i,int j) = 0;
86
87     /// access a element, no modify
88     virtual Real elem (int i, int j) const = 0;
89
90     virtual Array<Real> row (int i) const ;
91     virtual Array<Real> column (int j) const;
92
93     
94     /**
95     add a row to the matrix before  row k. Contents
96     of added row are unspecified
97
98       0 <= k <= rows()
99     */
100     virtual void insert_row (int k)=0;
101
102     
103       /**
104       delete a row from this matrix.
105
106       PRE
107       0 <= k < rows();
108     */
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;
113
114
115     
116     /**
117       at end of matrix?. when doing loop
118
119       for (i=0; i<h; i++)
120         for (j=0; j<w; j++)
121           ..
122
123     */
124     virtual bool mult_ok (int i, int j) const=0;
125
126     /**
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.
130     
131       PRE
132       mult_ok (i,j)
133      */
134     virtual void mult_next (int &i, int &j) const  = 0;
135
136     /**
137       valid matrix entry. return false if at end of row
138     */
139     virtual bool trans_ok (int i, int j) const=0;
140
141     /**
142       walk through matrix (transposed multiply).
143       Get next i (for column j)
144     
145       PRE
146       ver_ok (i,j)
147      */
148
149     virtual void trans_next (int &i, int &j) const  = 0;
150     
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 ;
157     /**
158       RTTI.
159      */
160     DECLARE_MY_RUNTIME_TYPEINFO;
161
162     
163     static Matrix_storage* get_product_result (Matrix_storage *left, 
164                                               Matrix_storage *right);
165     
166     
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);
171 };
172
173 #endif // MATRIX_STORAGE_HH
174