2 matrix.hh -- declare Matrix
4 source file of the Flower Library
6 (c) 1996, 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
13 #include "full-storage.hh"
17 /** a Real matrix. This is a class for a nonsquare block of #Real#s. The
18 implementation of sparse matrices is done in the appropriate #smat#
19 class. Matrix only does the mathematical actions (adding,
24 implement ref counting? */
28 friend Matrix
operator *(Matrix
const &m1
, Matrix
const &m2
);
32 void set (Matrix_storage
*);
34 void OK() const { dat_
->OK(); }
36 int calc_band_i () const;
37 int cols() const { return dat_
->cols (); }
38 int rows() const { return dat_
->rows (); }
40 /** return the size of a matrix.
42 the matrix needs to be square.
47 the band size of the matrix.
58 void set_diag (Real d
);
60 void set_diag (Vector d
);
62 void unit() { set_diag (1.0); }
64 void operator+=(Matrix
const &m
);
65 void operator-=(Matrix
const &m
);
66 void operator*=(Real a
);
67 void operator/=(Real a
) { (*this) *= 1/a
; }
70 add a row to the matrix before row k
76 void insert_row (Vector v
,int k
);
78 delete a row from this matrix.
83 void delete_row (int k
) { dat_
->delete_row (k
); }
84 void delete_column (int k
) { dat_
->delete_column (k
); }
87 square n matrix, initialised to null
92 n x m matrix, init to 0
94 Matrix (int n
, int m
);
95 Matrix (Matrix
const &m
);
97 /// dyadic product: v * w.transpose
98 Matrix (Vector v
, Vector w
);
99 void operator=(Matrix
const &m
);
101 /// access an element
102 Real
operator()(int i
,int j
) const { return dat_
->elem (i
,j
); }
104 /// access an element
105 Real
&operator()(int i
, int j
) { return dat_
->elem (i
,j
); }
107 /// Matrix multiply with vec (from right)
108 Vector
operator *(Vector
const &v
) const;
110 /// set this to m1*m2.
111 void set_product (Matrix
const &m1
, Matrix
const &m2
);
113 Vector
left_multiply (Vector
const &) const;
115 Matrix
operator-() const;
120 /// return a transposed copy.
121 Matrix
transposed() const ;
128 void swap_columns (int c1
, int c2
);
134 void swap_rows (int c1
, int c2
);
137 Vector
row (int) const;
138 Vector
col (int) const;
146 operator *(Vector
&v
, Matrix
const & m
) { return m
.left_multiply (v
); }
147 Matrix
operator *(Matrix
const & m1
,Matrix
const &m2
);
148 Matrix
operator /(Matrix
const &m1
,Real a
);
149 inline Matrix
operator -(Matrix m1
,const Matrix m2
)
154 inline Matrix
operator +(Matrix m1
,const Matrix m2
)