2 matrix.hh -- declare Matrix
4 source file of the Flower Library
6 (c) 1996,1997 Han-Wen Nienhuys <hanwen@stack.nl>
13 #include "matrix-storage.hh"
16 /** a Real matrix. This is a class for a nonsquare block of #Real#s. The
17 implementation of sparse matrices is done in the appropriate #smat#
18 class. Matrix only does the mathematical actions (adding,
23 implement ref counting? */
27 friend Matrix operator *(Matrix const &m1, Matrix const &m2);
31 void set (Matrix_storage*);
32 Matrix (Matrix_storage*);
34 void OK() const { dat->OK(); }
35 int cols() const { return dat->cols (); }
36 int rows() const { return dat->rows (); }
38 /** return the size of a matrix.
40 the matrix needs to be square.
45 the band size of the matrix.
52 void set_full() const;
53 void try_set_band() const;
54 ~Matrix() { delete dat; }
60 void set_diag (Real d);
62 void set_diag (Vector d);
64 void unit() { set_diag (1.0); }
66 void operator+=(Matrix const &m);
67 void operator-=(Matrix const &m);
68 void operator*=(Real a);
69 void operator/=(Real a) { (*this) *= 1/a; }
72 add a row to the matrix before row k
78 void insert_row (Vector v,int k);
80 delete a row from this matrix.
85 void delete_row (int k) { dat->delete_row (k); }
86 void delete_column (int k) { dat->delete_column (k); }
89 square n matrix, initialised to null
94 n x m matrix, init to 0
96 Matrix (int n, int m);
97 Matrix (Matrix const &m);
99 /// dyadic product: v * w.transpose
100 Matrix (Vector v, Vector w);
101 void operator=(Matrix const &m);
103 /// access an element
104 Real operator()(int i,int j) const { return dat->elem (i,j); }
106 /// access an element
107 Real &operator()(int i, int j) { return dat->elem (i,j); }
109 /// Matrix multiply with vec (from right)
110 Vector operator *(Vector const &v) const;
112 /// set this to m1*m2.
113 void set_product (Matrix const &m1, Matrix const &m2);
116 Vector left_multiply (Vector const &) const;
118 Matrix operator-() const;
123 /// return a transposed copy.
124 Matrix transposed() const ;
131 void swap_columns (int c1, int c2);
137 void swap_rows (int c1, int c2);
140 Vector row (int) const;
141 Vector col (int) const;
143 operator String() const;
148 operator *(Vector &v, Matrix const & m) { return m.left_multiply (v); }
149 Matrix operator *(Matrix const & m1,Matrix const &m2);
150 Matrix operator /(Matrix const &m1,Real a);
151 inline Matrix operator -(Matrix m1,const Matrix m2)
156 inline Matrix operator +(Matrix m1,const Matrix m2)