]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/matrix-storage.hh
release: 0.0.46.jcn1
[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 "class-name.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       
44     /**  set the size. contents lost.       
45       PRE
46       i >=0, j>=0
47     */
48     virtual void set_size(int rows, int cols) = 0;
49  
50     /**set the size to square dimen. contents lost
51       PRE
52       i>=0
53     */
54     virtual void set_size(int i) = 0;
55      /**set the size to i.
56
57       keep contents. If enlarged contents unspecified
58         
59       PRE
60       i>=0, j>=0
61     
62     */
63     virtual void resize(int rows, int cols ) = 0;
64  
65   /**    
66     set the size to square dimen. contents kept
67     Keep contents. If enlarged contents are unspecified
68     
69     PRE
70     i>=0  
71     */
72     virtual void resize(int i) = 0;
73   
74     
75         /**
76     access an element.
77
78     Generate an errormessage, if this happens
79     in the 0-part of a sparse matrix.
80     */
81
82     virtual Real& elem(int i,int j) = 0;
83
84     /// access a element, no modify
85     virtual Real const & elem(int i, int j) const = 0;
86
87     virtual Array<Real> row(int i) const = 0;
88     virtual Array<Real> column(int j) const = 0;
89
90     
91     /**
92     add a row to the matrix before  row k. Contents
93     of added row are unspecified
94
95       0 <= k <= rows()
96     */
97     virtual void insert_row(int k)=0;
98
99     
100       /**
101       delete a row from this matrix.
102
103       PRE
104       0 <= k < rows();
105     */
106     virtual void delete_row(int k)=0;
107         virtual void delete_column(int k)=0;
108     virtual ~Matrix_storage() { }
109     virtual Matrix_storage *clone()=0;
110
111
112     
113     /**
114       at end of matrix?. when doing loop
115
116       for(i=0; i<h; i++)
117         for(j=0; j<w; j++)
118           ..
119
120     */
121     virtual bool mult_ok(int i, int j) const=0;
122
123     /**
124       walk through matrix (regular multiply).
125       get next j for row i, or get next row i and reset j.
126       this will make sparse matrix implementation easy.
127     
128       PRE
129       mult_ok(i,j)
130      */
131     virtual void mult_next(int &i, int &j) const  = 0;
132
133 /**
134       valid matrix entry. return false if at end of row
135     */
136     virtual bool trans_ok(int i, int j) const=0;
137
138     /**
139       walk through matrix (transposed multiply).
140       Get next i (for column j)
141     
142       PRE
143       ver_ok(i,j)
144      */
145
146     virtual void trans_next(int &i, int &j) const  = 0;
147     /// generate a "Full_storage" matrix    
148     static Matrix_storage *get_full(int n, int m);
149     
150
151     virtual bool try_right_multiply(Matrix_storage *dest, 
152                                     const Matrix_storage *fact) ;
153     /**
154       RTTI.
155      */
156     NAME_MEMBERS(Matrix_storage);
157 };
158
159
160
161 inline bool
162 Matrix_storage::try_right_multiply(Matrix_storage *, 
163                                     const Matrix_storage *)
164 {
165     return false;
166 }
167 #endif // MATRIX_STORAGE_HH
168