]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/matrix-storage.hh
release: 1.0.1
[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--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9
10 #ifndef MATRIX_STORAGE_HH
11 #define MATRIX_STORAGE_HH
12
13 #include "array.hh"
14 #include "real.hh"
15
16 /** 
17
18     base class for interface with matrix storageclasses.  There are no
19     iterators for matrixclasses, since matrices are (like arrays)
20     explicitly int-indexed.
21
22     Iteration is provided by *_next, *_ok, which update and check both
23     index variables simultaneously.
24
25     TODO
26     determine type of product matrix.
27
28 */
29 class Matrix_storage {
30     
31
32 public:
33   /// check invariants
34   void OK() const;
35     
36   /// height of matrix
37   int rows() const;
38
39   /// width of matrix
40   int cols() const;
41
42   /// size if square
43   int dim() const;
44       
45   /**  set the size. contents lost.       
46        PRE
47        i >=0, j>=0
48   */
49   void set_size (int rows, int cols) ;
50
51  
52   /**set the size to square dimen. contents lost
53      PRE
54      i>=0
55   */
56   void set_size (int i) ;
57   /**set the size to i.
58
59      keep contents. If enlarged contents unspecified
60         
61      PRE
62      i>=0, j>=0
63     
64   */
65   void resize (int rows, int cols);
66  
67   /**    
68          set the size to square dimen. contents kept
69          Keep contents. If enlarged contents are unspecified
70     
71          PRE
72          i>=0  
73   */
74   void resize (int i);
75   
76     
77   /**
78      access an element.
79
80      Generate an errormessage, if this happens
81      in the 0-part of a sparse matrix.
82   */
83
84   Real& elem (int i,int j);
85
86   /// access a element, no modify
87   Real elem (int i, int j) const;
88
89   Array<Real> row (int i) const ;
90   Array<Real> column (int j) const;
91
92     
93   /**
94      add a row to the matrix before  row k. Contents
95      of added row are unspecified
96
97      0 <= k <= rows()
98   */
99   void insert_row (int k);
100
101     
102   /**
103      delete a row from this matrix.
104
105      PRE
106      0 <= k < rows();
107   */
108   void delete_row (int k);
109   void delete_column (int k);
110   ~Matrix_storage() { }
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   bool mult_ok (int i, int j) const;
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   void mult_next (int &i, int &j) const;
132
133   /**
134      valid matrix entry. return false if at end of row
135   */
136   bool trans_ok (int i, int j) const;
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   void trans_next (int &i, int &j) const;
147     
148   /// generate a "Full_storage" matrix    
149   static void set_band (Matrix_storage*&, int band);
150 };
151
152 #endif // MATRIX_STORAGE_HH
153