41#include "EST_TMatrix.h"
45#include "EST_matrix_support.h"
46#include "EST_TVector.h"
47#include "EST_cutils.h"
83 T *
memory,
int offset,
int free_when_destroyed)
123 a.p_row_step, a.p_column_step,
130 int r_step,
int c_step,
131 int start_r,
int num_r,
132 int start_c,
int num_c
135 for(
int r=start_r, i=0, rp=0; i< num_r; i++, r++, rp+=r_step)
136 for(
int c=start_c, j=0, cp=0; j< num_c; j++, c++, cp+=c_step)
141void EST_TMatrix<T>::get_values(T *data,
142 int r_step,
int c_step,
143 int start_r,
int num_r,
144 int start_c,
int num_c
147 for(
int r=start_r, i=0, rp=0; i< num_r; i++, r++, rp+=r_step)
148 for(
int c=start_c, j=0, cp=0; j< num_c; j++, c++, cp+=c_step)
155 resize(a.num_rows(), a.num_columns(), 0);
170 EST_error(
"Can't add rows with different number of columns (%d vs %d)",
179 for(
int i=old_num_rows, i1=0; i<
num_rows(); i++, i1++)
191 EST_error(
"Can't add columns with different number of rows (%d vs %d)",
200 for(
int i=old_num_columns, i1=0; i<
num_columns(); i++, i1++)
217 if (this->p_sub_matrix)
218 EST_error(
"Attempt to resize Sub-Matrix");
220 if (new_cols < 0 || new_rows < 0)
221 EST_error(
"Attempt to resize matrix to negative size: %d x %d",
226 new_m =
new T[new_rows*new_cols];
230 if (old_vals != NULL)
232 else if (!this->p_sub_matrix)
236 p_num_rows = new_rows;
237 this->p_num_columns = new_cols;
240 this->p_column_step=1;
245 *old_vals = this->p_memory;
258 int old_column_step = this->p_column_step;
272 if (old_vals != NULL)
278 old_row_step, old_column_step,
288 for(i=0; i<copy_r; i++)
289 for(j=copy_c; j<new_cols; j++)
292 for(i=copy_r; i<new_rows; i++)
293 for(j=0; j<new_cols; j++)
297 if (old_vals && old_vals != this->p_memory && !this->p_sub_matrix)
298 delete [] (old_vals-old_offset);
302bool EST_TMatrix<T>::have_rows_before(
int n)
const
304 return this->p_offset >= n*p_row_step;
308bool EST_TMatrix<T>::have_columns_before(
int n)
const
328 if (filename ==
"-" || filename ==
"")
331 outf =
new ofstream(filename);
341 <<
"r'="<<((
int)((T *) mx_move_pointer_f(this->
p_memory,
sizeof(T)*
p_row_step, i)))<<
","
343 <<
"c="<<((
int)mx_move_pointer(this->
p_memory, T, this->p_column_step, j))<<
","
344 <<((int)(&fast_a_m_gcc(i,j)))
365 EST_error(
"Matrix loading not implemented yet.");
366 return misc_read_error;
372 int rows,
int columns,
373 int free_when_destroyed)
375 EST_TVector<T>::set_memory(buffer, offset, columns, free_when_destroyed);
382 int offset,
int num)
const
394 for (
int j = offset; j < to; j++)
400 int offset,
int num)
const
414 for (
int j = offset; j < to; j++)
421 int offset,
int num)
const
426 int to = num >= 0 ? offset + num :
num_rows();
436 for (
int i = offset; i < to; i++)
443 int offset,
int num)
const
448 int to = num >= 0 ? offset + num :
num_rows();
460 for (
int i = offset; i < to; i++)
473 for(
int j=offset; j<to; j++)
480 int to = num>=0?offset+num:
num_rows();
485 for(
int i=offset; i<to; i++)
494 int to = num>=0?offset+num:num_columns();
496 if (!EST_matrix_bounds_check(r, 0, num_rows(), num_columns(), TRUE))
507 for(
int j=offset; j<to; j++)
508 fast_a_m(r, j) = from.
fast_a_m(from_r, (j-offset)+from_offset);
516 int to = num>=0?offset+num:num_rows();
518 if (!EST_matrix_bounds_check(0, c, num_rows(), num_columns(), TRUE))
529 for(
int i=offset; i<to; i++)
530 fast_a_m(i, c) = from.
fast_a_m((i-offset)+from_offset, from_c);
542 if (rv.
p_memory != NULL && ! rv.p_sub_matrix)
545 rv.p_sub_matrix = TRUE;
552 rv.p_column_step=this->p_column_step;
564 if (cv.
p_memory != NULL && ! cv.p_sub_matrix)
567 cv.p_sub_matrix = TRUE;
579 int r,
int len_r,
int c,
int len_c)
589 if (sm.
p_memory != NULL && ! sm.p_sub_matrix)
592 sm.p_sub_matrix = TRUE;
596 sm.p_column_step=this->p_column_step;
EST_TMatrix & operator=(const EST_TMatrix &s)
assignment operator
void copy_row(int r, T *buf, int offset=0, int num=-1) const
int num_columns() const
return number of columns
EST_read_status load(const class EST_String &filename)
load Matrix from file - Not currently implemented.
unsigned int p_num_rows
Visible shape.
void fill(const T &v)
fill matrix with value v
void set_values(const T *data, int r_step, int c_step, int start_r, int num_r, int start_c, int num_c)
Get and set values from array.
INLINE const T & a_no_check(int row, int col) const
const access with no bounds check, care recommend
void sub_matrix(EST_TMatrix< T > &sm, int r=0, int numr=EST_ALL, int c=0, int numc=EST_ALL)
Make the matrix {\tt sm} a window into this matrix.
void default_vals()
sets data and length to default values (0 in both cases).
void set_row(int n, const T *buf, int offset=0, int num=-1)
int num_rows() const
return number of rows
void just_resize(int new_rows, int new_cols, T **old_vals)
resize the memory and reset the bounds, but don't set values.
void copy_data(const EST_TMatrix< T > &a)
just copy data, no resizing, no size check.
void set_memory(T *buffer, int offset, int rows, int columns, int free_when_destroyed=0)
void row(EST_TVector< T > &rv, int r, int start_c=0, int len=-1)
Make the vector {\tt rv} a window onto row {\tt r}.
unsigned int p_row_step
How to access the memory.
const T & a_check(int row, int col) const
const element access function
~EST_TMatrix()
EST_TMatrix.
EST_TMatrix()
default constructor
void copy(const EST_TMatrix< T > &a)
private resize and copy function.
void set_column(int n, const T *buf, int offset=0, int num=-1)
void resize(int rows, int cols, int set=1)
EST_TMatrix & add_rows(const EST_TMatrix &s)
The two versions of what might have been operator +=.
EST_write_status save(const class EST_String &filename) const
save Matrix to file {\tt filename}
void column(EST_TVector< T > &cv, int c, int start_r=0, int len=-1)
Make the vector {\tt cv} a window onto column {\tt c}.
void copy_column(int c, T *buf, int offset=0, int num=-1) const
INLINE const T & fast_a_m(int r, int c) const
quick method for returning {\tt x[m][n]}
void resize(int n, int set=1)
void default_vals()
sets data and length to default values (0 in both cases).
static const double * def_val
unsigned int p_num_columns
EST_TVector()
default constructor