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? */
30 void OK() const { dat->OK(); }
31 int cols() const { return dat->cols(); }
32 int rows() const { return dat->rows(); }
34 /** return the size of a matrix.
36 the matrix needs to be square.
40 // Matrix() { dat = 0; }
41 ~Matrix() { delete dat; }
47 void set_diag(Real d);
49 void set_diag(Vector d);
51 void unit() { set_diag(1.0); }
53 void operator+=(Matrix const &m);
54 void operator-=(Matrix const &m);
55 void operator*=(Real a);
56 void operator/=(Real a) { (*this) *= 1/a; }
59 add a row to the matrix before row k
65 void insert_row(Vector v,int k);
67 delete a row from this matrix.
72 void delete_row(int k) { dat->delete_row(k); }
73 void delete_column(int k) { dat->delete_column(k); }
76 square n matrix, initialised to null
81 n x m matrix, init to 0
84 Matrix(Matrix const &m);
86 /// dyadic product: v * w.transpose
87 Matrix(Vector v, Vector w);
88 void operator=(Matrix const &m);
91 Real operator()(int i,int j) const { return dat->elem(i,j); }
94 Real &operator()(int i, int j) { return dat->elem(i,j); }
96 /// Matrix multiply with vec (from right)
97 Vector operator *(Vector const &v) const;
99 /// set this to m1*m2.
100 void set_product(Matrix const &m1, Matrix const &m2);
103 Vector left_multiply(Vector const &) const;
105 Matrix operator-() const;
110 /// return a transposed copy.
111 Matrix transposed() const ;
118 void swap_columns(int c1, int c2);
124 void swap_rows(int c1, int c2);
127 Vector row(int ) const;
128 Vector col(int) const;
130 operator String() const;
135 operator *(Vector &v, Matrix const & m) { return m.left_multiply(v); }
136 Matrix operator *(Matrix const & m1,Matrix const &m2);
137 Matrix operator /(Matrix const &m1,Real a);
138 inline Matrix operator -(Matrix m1,const Matrix m2)