add $(EXEEXT) to executable targets during installation for MinGW
[suif.git] / src / baseparsuif / suifmath / fract_matrix.h
blob2a97d97857abf34166efe3a81b36404ce9a2a5d4
1 /* file "fract_matrix.h" */
3 /* Copyright (c) 1994,95 Stanford University
5 All rights reserved.
7 This software is provided under the terms described in
8 the "suif_copyright.h" include file. */
10 #include <suif_copyright.h>
13 // Two dimensional fractional matrix class.
15 // Each matrix is made up of an array of fract_vectors, where each
16 // fract_vector is a column of the matrix.
19 #ifndef FRACT_MATRIX_H
20 #define FRACT_MATRIX_H
22 #pragma interface
24 #include <suif1.h>
25 #include "int_matrix.h"
26 #include "fract.h"
27 #include "fract_vector.h"
29 RCS_HEADER(fract_matrix_h, "$Id: fract_matrix.h,v 1.1.1.1 1998/07/07 05:09:27 brm Exp $")
31 class matrix;
32 class fract_matrix;
33 fract_matrix cvt_fract_matrix(immed_list *il);
35 class fract_matrix {
36 friend class matrix;
37 private:
38 int rows;
39 int cols;
40 fract_vector *col_list;
42 void create_columns(); // create fract_vectors for cols
43 void copy_fract_matrix(const fract_matrix &mat); // copy mat into this
44 void copy_int_matrix(const integer_matrix &mat);
45 // copy integer_matrix into this
47 public:
48 fract_matrix();
49 fract_matrix(int r, int c);
50 fract_matrix(const integer_matrix &mat);
51 fract_matrix(const integer_matrix &mat, int div);
52 fract_matrix(const fract_matrix &mat);
53 fract_matrix(const fract_matrix &mat, int c);
54 // (c <= mat.n()) result is first c cols of mat
55 // (c > mat.n()) result is mat, with (c - mat.m()) cols of 0's appended
57 ~fract_matrix() { clear(); }
59 int m() const { return rows; }
60 int n() const { return cols; }
62 fract &elt(int r, int c)
63 { assert (r >= 0 && r < rows && c >= 0 && c < cols);
64 return col_list[c][r]; }
66 const fract &rc(int r, int c) const
67 { assert (r >= 0 && r < rows && c >= 0 && c < cols);
68 return col_list[c][r]; }
71 // Equality and assignment operators:
73 boolean operator==(const fract_matrix &mat) const;
74 boolean operator!=(const fract_matrix &mat) const
75 { return (!((*this) == mat)); }
76 fract_matrix & operator=(const fract_matrix &mat);
79 // Matrix-Matrix operations:
81 fract_matrix operator+(const fract_matrix &mat) const;
82 fract_matrix operator-(const fract_matrix &mat) const;
83 fract_matrix operator*(const fract_matrix &mat) const;
84 fract_matrix & operator+=(const fract_matrix &mat);
85 fract_matrix & operator-=(const fract_matrix &mat);
88 // Element-wise operations:
90 fract_matrix operator*(fract val) const;
91 fract_matrix operator/(fract val) const;
92 fract_matrix operator+(fract val) const;
93 fract_matrix operator-(fract val) const;
95 fract_matrix & operator+=(fract val);
96 fract_matrix & operator-=(fract val);
97 fract_matrix & operator*=(fract val);
98 fract_matrix & operator/=(fract val);
101 // Matrix-vector
103 fract_vector operator*(const fract_vector &vec) const;
106 // Other useful functions:
108 void ident(int n); // overwrites 'this' with an nxn identity matrix
109 void ident() { assert(rows == cols); ident(rows); }
111 fract_matrix transpose() const;
112 // returns transpose, does not modify 'this'
115 // General utilities
117 fract_matrix operator%(const integer_row &rw) const;
118 // shuffle each column:
119 // ret[x,i] = this[rw[x],i]
121 fract_matrix del_row(int i, int j) const; // deletes rows i to j, inclusive
122 fract_matrix del_row(int i) const { return del_row(i, i); }
125 fract_matrix del_col(int i, int j) const; // deletes cols i to j, inclusive
126 fract_matrix del_col(int i) const { return del_col(i, i); }
128 fract_matrix del_columns(const integer_row &rw) const;
129 // delete cols w/ rw as mask
130 fract_matrix insert_col(int i) const; // insert new col at pos i
131 fract_matrix swap_col(int i, int j) const; // switches cols i and j
132 fract_matrix swap_row(int i, int j) const; // switches rows i and j
133 fract_vector get_row(int i) const;
134 fract_vector get_col(int i) const;
135 void set_row(int i, const fract_vector &vec);
136 void set_col(int i, const fract_vector &vec);
138 // resize_offset returns a (this->m()-r1+r2 x this->n()-c1+c2) matrix.
139 // If (r2 > 0) the matrix is formed with rows r1..m()-1, with r2 extra
140 // rows appended. The elements in the appended rows are set
141 // to 'fill'.
142 // If (r2 < 0) the matrix is formed with rows r1..m()-r2.
143 // The columns are set in the same way as the rows.
145 // resize returns a (r1+r2 x c1+c2) matrix.
146 // The matrix is formed with rows r1..r2. If (r2 > m()) then
147 // r2-mm rows are appended. The elements in the appended rows
148 // are set to 'fill'.
149 // The columns are set in the same way as the rows.
151 fract_matrix resize_offset(int r1, int r2, int c1, int c2, int fill = 0)
152 const;
153 fract_matrix resize(int r1, int r2, int c1, int c2, int fill = 0)
154 { return resize_offset(r1, r2-rows, c1, c2-cols, fill); }
156 // c_merge returns the (this->m() x (this->n() + mat.n()))
157 // matrix formed by merging 'this' and mat, rowwise
158 // r_merge returns the ((this->m() + mat.m()) x this->n())
159 // matrix formed by merging m1 and m2, columnwise.
161 fract_matrix r_merge(const fract_matrix &mat) const;
162 fract_matrix c_merge(const fract_matrix &mat) const;
164 fract_matrix operator|(const fract_matrix &mat) const
165 { return c_merge(mat); }
166 fract_matrix operator&(const fract_matrix &mat) const
167 { return r_merge(mat); }
169 immed_list *cvt_immed_list() const;
170 friend fract_matrix cvt_fract_matrix(immed_list *il);
171 void print(FILE *fp = stdout) const;
172 void clear();
176 #endif /* FRACT_MATRIX_H */