48 #include "EST_rw_status.h"
49 #include "EST_TVector.h"
50 #include "instantiate/EST_TMatrixI.h"
53 #ifndef TMATRIX_BOUNDS_CHECKING
54 # define TMATRIX_BOUNDS_CHECKING 0
57 #if TMATRIX_BOUNDS_CHECKING
58 #define A_CHECK a_check
60 #define A_CHECK a_no_check
68 #if defined(__GNUC__) && 0
69 # define mx_move_pointer(P, TY, STEP, N) \
71 ((void *) (((char (*) [sizeof(TY)*STEP])P) + N) ) \
73 # define fast_a_m_gcc(R,C) \
74 ( * mx_move_pointer(mx_move_pointer(p_memory,T,p_column_step,C),T,p_row_step,R))
75 # define fast_a_m_x(R,C) (fast_a_m_gcc(R,C))
77 # define fast_a_m_x(R,C) (fast_a_m(R,C))
100 INLINE
unsigned int mcell_pos(
int r,
int c,
101 int rs,
int cs)
const
102 {
return (rs==1?r:(r*rs)) + (cs==1?c:(c*cs));}
105 INLINE
unsigned int mcell_pos(
int r,
int c)
const
108 return mcell_pos(r, c,
109 this->p_row_step, this->p_column_step);
112 INLINE
unsigned int mcell_pos_1(
int r,
int c)
const
121 {
return this->p_memory[mcell_pos(r,c)]; }
122 INLINE T &fast_a_m(
int r,
int c)
123 {
return this->p_memory[mcell_pos(r,c)]; }
125 INLINE
const T &fast_a_1(
int r,
int c)
const
126 {
return this->p_memory[mcell_pos_1(r,c)]; }
127 INLINE T &fast_a_1(
int r,
int c)
128 {
return this->p_memory[mcell_pos_1(r,c)]; }
132 void set_values(
const T *data,
133 int r_step,
int c_step,
134 int start_r,
int num_r,
135 int start_c,
int num_c
137 void get_values(T *data,
138 int r_step,
int c_step,
139 int start_r,
int num_r,
140 int start_c,
int num_c
149 void just_resize(
int new_rows,
int new_cols, T** old_vals);
166 T *memory,
int offset=0,
int free_when_destroyed=0);
184 {
return fast_a_m_x(row,col); }
187 {
return fast_a_m_x(row,col); }
189 INLINE
const T &a_no_check_1(
int row,
int col)
const {
return fast_a_1(row,col); }
190 INLINE T &a_no_check_1(
int row,
int col) {
return fast_a_1(row,col); }
193 const T &a_check(
int row,
int col)
const;
195 T &a_check(
int row,
int col);
197 const T &a(
int row,
int col)
const {
return A_CHECK(row,col); }
198 T &a(
int row,
int col) {
return A_CHECK(row,col); }
201 const T &operator () (
int row,
int col)
const {
return a(row,col); }
203 T &operator () (
int row,
int col) {
return a(row,col); }
207 bool have_rows_before(
int n)
const;
208 bool have_columns_before(
int n)
const;
215 void resize(
int rows,
int cols,
int set=1);
218 void fill(
const T &v);
219 void fill() { fill(*this->def_val); }
239 void column(
EST_TVector<T> &cv,
int c,
int start_r=0,
int len=-1);
242 int r=0,
int numr=EST_ALL,
243 int c=0,
int numc=EST_ALL);
253 void copy_row(
int r, T *buf,
int offset=0,
int num=-1)
const;
259 void copy_row(
int r,
EST_TVector<T> &t,
int offset=0,
int num=-1)
const;
264 void copy_column(
int c, T *buf,
int offset=0,
int num=-1)
const;
270 void copy_column(
int c,
EST_TVector<T> &t,
int offset=0,
int num=-1)
const;
274 void set_row(
int n,
const T *buf,
int offset=0,
int num=-1);
276 void set_row(
int n,
const EST_TVector<T> &t,
int offset=0,
int num=-1)
277 { set_row(n, t.
memory(), offset, num); }
281 int offset=0,
int num=-1);
286 void set_column(
int n,
const T *buf,
int offset=0,
int num=-1);
288 void set_column(
int n,
const EST_TVector<T> &t,
int offset=0,
int num=-1)
289 { set_column(n, t.
memory(), offset, num); }
291 void set_column(
int c,
293 int offset=0,
int num=-1);
297 void set_memory(T *buffer,
int offset,
int rows,
int columns,
298 int free_when_destroyed=0);
306 EST_read_status load(
const class EST_String &filename);
308 EST_write_status save(
const class EST_String &filename)
const;
311 friend ostream& operator << (ostream &st,const EST_TMatrix<T> &a)
313 for (i = 0; i < a.num_rows(); ++i) {
314 for (j = 0; j < a.num_columns(); ++j)
315 st << a.a_no_check(i, j) <<
" "; st << endl;
INLINE const T & a_no_check(int row, int col) const
const access with no bounds check, care recommend
int num_columns() const
return number of columns
Template Matrix class. This is an extension of the EST_TVector class to two dimensions.
INLINE T & a_no_check(int row, int col)
access with no bounds check, care recommend
unsigned int p_row_step
How to access the memory.
unsigned int p_num_rows
Visible shape.
int num_rows() const
return number of rows
INLINE const T & fast_a_m(int r, int c) const
quick method for returning x[m][n]