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