41#include "EST_TMatrix.h"
45#include "EST_matrix_support.h"
46#include "EST_TVector.h"
47#include "EST_cutils.h"
103 if (!EST_matrix_bounds_check(row, col, num_rows(), num_columns(), FALSE))
104 return *this->error_return;
106 return a_no_check(row,col);
122 set_values(a.p_memory,
123 a.p_row_step, a.p_column_step,
137 a_no_check(r,c) = data[
rp+
cp];
149 data[
rp+
cp] = a_no_check(r,c);
155 resize(a.num_rows(), a.num_columns(), 0);
169 if (
in.num_columns() != num_columns())
170 EST_error(
"Can't add rows with different number of columns (%d vs %d)",
177 resize(num_rows()+
in.num_rows(), num_columns(), TRUE);
180 for(
int j=0;
j<num_columns();
j++)
190 if (
in.num_rows() != num_rows())
191 EST_error(
"Can't add columns with different number of rows (%d vs %d)",
198 resize(num_columns()+
in.num_columns(), num_rows(), TRUE);
201 for(
int j=0;
j<num_rows();
j++)
215 if (num_rows() !=
new_rows || num_columns() !=
new_cols || this->p_memory == NULL )
217 if (this->p_sub_matrix)
218 EST_error(
"Attempt to resize Sub-Matrix");
221 EST_error(
"Attempt to resize matrix to negative size: %d x %d",
228 if (this->p_memory != NULL)
232 else if (!this->p_sub_matrix)
233 delete [] (this->p_memory-this->p_offset);
239 p_row_step=this->p_num_columns;
240 this->p_column_step=1;
290 a_no_check(i,
j) = *this->def_val;
294 a_no_check(i,
j) = *this->def_val;
304 return this->p_offset >= n*p_row_step;
310 return this->p_offset >= n*this->p_column_step;
317 for (i = 0; i < num_rows(); ++i)
318 for (
j = 0;
j < num_columns(); ++
j)
328 if (filename ==
"-" || filename ==
"")
333 for (i = 0; i < num_rows(); ++i)
335 for (
j = 0;
j < num_columns(); ++
j)
340 <<
",m="<<((int)this->p_memory)<<
","
347 << a_no_check(i,
j) <<
"\t";
365 EST_error(
"Matrix loading not implemented yet.");
366 return misc_read_error;
382 int offset,
int num)
const
384 int to =
num >= 0 ? offset +
num : num_columns();
386 if (!EST_matrix_bounds_check(r, 0, num_rows(), num_columns(), FALSE))
394 for (
int j = offset;
j < to;
j++)
395 buf[
j-offset] = fast_a_m(r,
j);
400 int offset,
int num)
const
402 int to =
num >= 0 ? offset +
num : num_columns();
404 if (!EST_matrix_bounds_check(r, 0, num_rows(), num_columns(), FALSE))
412 buf.resize(to - offset);
414 for (
int j = offset;
j < to;
j++)
415 buf[
j - offset] = fast_a_m(r,
j);
421 int offset,
int num)
const
426 int to =
num >= 0 ? offset +
num : num_rows();
428 if (!EST_matrix_bounds_check(0, c, num_rows(), num_columns(), FALSE))
436 for (
int i = offset; i < to; i++)
437 buf[i-offset] = fast_a_m(i, c);
443 int offset,
int num)
const
448 int to =
num >= 0 ? offset +
num : num_rows();
450 if (!EST_matrix_bounds_check(0, c, num_rows(), num_columns(), FALSE))
452 if( num_columns()>0 )
458 buf.resize(to - offset);
460 for (
int i = offset; i < to; i++)
461 buf[i-offset] = fast_a_m(i, c);
468 int to =
num>=0?offset+
num:num_columns();
470 if (!EST_matrix_bounds_check(r, 0, num_rows(), num_columns(), TRUE))
473 for(
int j=offset;
j<to;
j++)
474 fast_a_m(r,
j) =
buf[
j-offset];
480 int to =
num>=0?offset+
num:num_rows();
482 if (!EST_matrix_bounds_check(0, c, num_rows(), num_columns(), TRUE))
485 for(
int i=offset; i<to; i++)
486 fast_a_m(i, c) =
buf[i-offset];
494 int to =
num>=0?offset+
num:num_columns();
496 if (!EST_matrix_bounds_check(r, 0, num_rows(), num_columns(), TRUE))
499 if (!EST_matrix_bounds_check(
from_r, 0, from.num_rows(), from.num_columns(), FALSE))
501 if (from.num_rows()>0)
507 for(
int j=offset;
j<to;
j++)
516 int to =
num>=0?offset+
num:num_rows();
518 if (!EST_matrix_bounds_check(0, c, num_rows(), num_columns(), TRUE))
521 if (!EST_matrix_bounds_check(0,
from_c, from.num_rows(), from.num_columns(), FALSE))
523 if (from.num_columns()>0)
529 for(
int i=offset; i<to; i++)
539 if (!EST_matrix_bounds_check(r, 1,
start_c,
len, num_rows(), num_columns(), 0))
542 if (
rv.p_memory != NULL && !
rv.p_sub_matrix)
543 delete [] (
rv.p_memory -
rv.p_offset);
545 rv.p_sub_matrix = TRUE;
546 rv.p_num_columns =
len;
547 rv.p_offset = this->p_offset +
start_c*this->p_column_step + r*p_row_step;
548 rv.p_memory = this->p_memory - this->p_offset +
rv.p_offset;
552 rv.p_column_step=this->p_column_step;
561 if (!EST_matrix_bounds_check(
start_r,
len, c, 1,num_rows(), num_columns(), 0))
564 if (
cv.p_memory != NULL && !
cv.p_sub_matrix)
565 delete [] (
cv.p_memory -
cv.p_offset);
567 cv.p_sub_matrix = TRUE;
568 cv.p_num_columns =
len;
569 cv.p_offset = this->p_offset + c*this->p_column_step +
start_r*p_row_step;
570 cv.p_memory = this->p_memory - this->p_offset +
cv.p_offset;
574 cv.p_column_step=p_row_step;
582 len_r = num_rows()-r;
584 len_c = num_columns()-c;
586 if (!EST_matrix_bounds_check(r,
len_r, c,
len_c, num_rows(), num_columns(), 0))
589 if (
sm.p_memory != NULL && !
sm.p_sub_matrix)
590 delete [] (
sm.p_memory -
sm.p_offset);
592 sm.p_sub_matrix = TRUE;
593 sm.p_offset = this->p_offset + c*this->p_column_step + r*p_row_step;
594 sm.p_memory = this->p_memory - this->p_offset +
sm.p_offset;
595 sm.p_row_step=p_row_step;
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
EST_read_status load(const class EST_String &filename)
load Matrix from file - Not currently implemented.
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.
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)
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}.
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
void default_vals()
sets data and length to default values (0 in both cases).