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