]> git.donarmstrong.com Git - lilypond.git/blob - flower/lib/include/vsmat.hh
release: 0.0.39-1
[lilypond.git] / flower / lib / include / vsmat.hh
1 #ifndef VSMAT_HH
2 #define VSMAT_HH
3 #include "varray.hh"
4 #include "real.hh"
5 /** base class for interface with matrix storageclasses.  There are no
6     iterators for matrixclasses, since matrices are (like arrays)
7     explicitly int-indexed.
8
9     Iteration is provided by *_next, *_ok, which update and check both
10     index variables simultaneously.
11
12     TODO
13     determine type of product matrix.
14
15 */
16 class virtual_smat {
17     
18
19 public:
20     /// check invariants
21     virtual void OK() const=0;
22     
23     /// height of matrix
24     virtual int rows() const = 0;
25
26     /// width of matrix
27     virtual int cols() const = 0;
28  
29       
30     /**  set the size. contents lost.       
31       PRE
32       i >=0, j>=0
33     */
34     virtual void set_size(int i, int j) = 0;
35  
36     /**set the size to square dimen. contents lost
37       PRE
38       i>=0
39     */
40     virtual void set_size(int i) = 0;
41      /**set the size to i.
42
43       keep contents. If enlarged contents unspecified
44         
45       PRE
46       i>=0, j>=0
47     
48     */
49     virtual void resize(int i, int j) = 0;
50  
51   /**    
52     set the size to square dimen. contents kept
53     Keep contents. If enlarged contents are unspecified
54     
55     PRE
56     i>=0  
57     */
58     virtual void resize(int i) = 0;
59   
60     
61         /**
62     access an element.
63
64     Generate an errormessage, if this happens
65     in the 0-part of a sparse matrix.
66     */
67
68     virtual Real& elem(int i,int j) = 0;
69
70     /// access a element, no modify
71     virtual const Real& elem(int i, int j) const = 0;
72
73 #if 1
74     virtual Array<Real> row(int i) const = 0;
75     virtual Array<Real> column(int j) const = 0;
76 #endif
77
78     
79     /**
80     add a row to the matrix before  row k. Contents
81     of added row are unspecified
82
83       0 <= k <= rows()
84     */
85     virtual void insert_row(int k)=0;
86
87     
88       /**
89       delete a row from this matrix.
90
91       PRE
92       0 <= k < rows();
93     */
94     virtual void delete_row(int k)=0;
95         virtual void delete_column(int k)=0;
96     virtual ~virtual_smat() { }
97     virtual virtual_smat *clone()=0;
98
99
100     
101     /**
102       at end of matrix?. when doing loop
103
104       for(i=0; i<h; i++)
105         for(j=0; j<w; j++)
106           ..
107
108     */
109     virtual bool mult_ok(int i, int j) const=0;
110
111     /**
112       walk through matrix (regular multiply).
113       get next j for row i, or get next row i and reset j.
114       this will make sparse matrix implementation easy.
115     
116       PRE
117       mult_ok(i,j)
118      */
119     virtual void mult_next(int &i, int &j) const  = 0;
120
121 /**
122       valid matrix entry. return false if at end of row
123     */
124     virtual bool trans_ok(int i, int j) const=0;
125
126     /**
127       walk through matrix (transposed multiply).
128       Get next i (for column j)
129     
130       PRE
131       ver_ok(i,j)
132      */
133
134     virtual void trans_next(int &i, int &j) const  = 0;
135     /// generate a "Full_storage" matrix    
136     static virtual_smat *get_full(int n, int m);
137
138 };
139     
140
141 #endif