Nemo  2.4.0
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
TMatrix Class Reference

A class to handle matrix in params, coerces matrix into a vector of same total size. More...

#include <tmatrix.h>

+ Collaboration diagram for TMatrix:

Public Member Functions

 TMatrix ()
 
 TMatrix (const TMatrix &mat)
 copy constructor. More...
 
 TMatrix (unsigned int rows, unsigned int cols)
 Creates an array of doubles of size = rows*cols. More...
 
 ~TMatrix ()
 
void copy (const TMatrix &mat)
 Copy a matrix. More...
 
void copy_recycle (const TMatrix &mat)
 Copy elements of 'mat', recycling elements of 'mat' if its size is smaller than current matrix. More...
 
void set (unsigned int i, unsigned int j, double val)
 Sets element at row i and column j to value val. More...
 
void set_row (unsigned int i, double val)
 Sets all elements at row i to value val. More...
 
void set_row (unsigned int i, vector< double > vec)
 Sets elements at row i to values stored in vector vec. More...
 
void set_col (unsigned int i, double val)
 Sets element at column i to value val. More...
 
void set_col (unsigned int i, vector< double > vec)
 Sets element at column i to values stored in vector vec. More...
 
void assign (double val)
 Assigns a value to all element of the matrix. More...
 
void reset (unsigned int rows, unsigned int cols)
 Re-allocate the existing matrix with assigned rows and cols dimensions and all elements to 0. More...
 
void reset (unsigned int rows, unsigned int cols, double value)
 Reset the existing matrix to the new dimensions and copies the value to all elements. More...
 
void reset (unsigned int rows, unsigned int cols, const double *array)
 Reset the existing matrix to the new dimensions and copies the array, which has to be of the same total length. More...
 
void reset ()
 Reset members to zero state. More...
 
double get (unsigned int i, unsigned int j) const
 Accessor to element at row i and column j. More...
 
double * get () const
 Accessor to the whole array. More...
 
double * getValArray () const
 
unsigned int get_dims (unsigned int *dims) const
 Accessor to the matrix dimensions. More...
 
unsigned int getNbRows () const
 Gives the number of rows. More...
 
unsigned int nrows () const
 
unsigned int getNbCols () const
 Gives the number of columns. More...
 
unsigned int ncols () const
 
unsigned int length () const
 Returns the number of elements in the matrix. More...
 
void getColumnView (unsigned int col, unsigned int n, double *array)
 Gives access to a column of the matrix. More...
 
void getRowView (unsigned int row, unsigned int n, double *array)
 Gives access to a row of the matrix. More...
 
void plus (unsigned int i, unsigned int j, double value)
 Adds a value to an element of the matrix. More...
 
void matrix_increment (double value)
 Adds a value to all elements in a matrix. More...
 
void sweep_plus (double value)
 Adds a value to all elements in a matrix. More...
 
void minus (unsigned int i, unsigned int j, double value)
 Substracts a value from an element of the matrix. More...
 
void sweep_minus (double value)
 Substracts a value to all elements in a matrix. More...
 
void multi (unsigned int i, unsigned int j, double value)
 Multiply an element of the matrix by a value. More...
 
void sweep_multiply (double value)
 multiply each element by a value. More...
 
void divide (unsigned int i, unsigned int j, double value)
 Divide an element of the matrix by a value. More...
 
void sweep_divide (double value)
 Divide all elements of the matrix by a value. More...
 
void transpose ()
 Transpose the matrix, swaps columns for rows. More...
 
double colSum (unsigned int col)
 Sum all elements in a column. More...
 
double rowSum (unsigned int row)
 Sum all elements in a row. More...
 
void show_up ()
 
string to_string ()
 Writes the matrix into a string in Nemo's matrix input format. More...
 

Private Attributes

unsigned int _rows
 
unsigned int _cols
 
unsigned int _length
 
double * _val
 

Detailed Description

A class to handle matrix in params, coerces matrix into a vector of same total size.

Constructor & Destructor Documentation

◆ TMatrix() [1/3]

TMatrix::TMatrix ( )
inline
58 : _rows(0), _cols(0), _length(0), _val(0) { }
unsigned int _cols
Definition: tmatrix.h:52
unsigned int _rows
Definition: tmatrix.h:52
double * _val
Definition: tmatrix.h:54
unsigned int _length
Definition: tmatrix.h:52

◆ TMatrix() [2/3]

TMatrix::TMatrix ( const TMatrix mat)
inline

copy constructor.

61  : _rows(0), _cols(0), _length(0), _val(0)
62  {
63  copy(mat);
64  }
void copy(const TMatrix &mat)
Copy a matrix.
Definition: tmatrix.h:77

◆ TMatrix() [3/3]

TMatrix::TMatrix ( unsigned int  rows,
unsigned int  cols 
)
inline

Creates an array of doubles of size = rows*cols.

67  : _rows(0), _cols(0), _length(0), _val(0)
68  {
69  _length = rows*cols;
70  _val = new double [_length];
71  _rows = rows; _cols = cols;
72  }

◆ ~TMatrix()

TMatrix::~TMatrix ( )
inline
74 {if(_val != NULL) delete [] _val;}

Member Function Documentation

◆ assign()

◆ colSum()

double TMatrix::colSum ( unsigned int  col)
inline

Sum all elements in a column.

344  {
345  assert(col < _cols); //has to be [0, _cols-1]
346  double sum = 0;
347  for (unsigned int i = 0; i < _rows; ++i) {
348  sum += _val[i*_cols + col];
349  }
350  return sum;
351  }

Referenced by TProtoQuanti::get_trait_mutation_variance().

+ Here is the caller graph for this function:

◆ copy()

void TMatrix::copy ( const TMatrix mat)
inline

Copy a matrix.

78  {
79  _rows = mat._rows;
80  _cols = mat._cols;
82  if(_val) delete [] _val;
83  _val = new double [_length];
84  memcpy(_val,mat._val,_length*sizeof(double));
85  }

References _cols, _rows, and _val.

Referenced by LCE_PhenotypeExpression::execute(), TTNOhtaStats::FHwrite(), TTQOhtaStats::FHwrite(), TProtoQuanti::setEpistasisParameters(), LCE_Breed_Wolbachia::setParameters(), Metapop::setPatchSizes(), and TProtoQuanti::TProtoQuanti().

+ Here is the caller graph for this function:

◆ copy_recycle()

void TMatrix::copy_recycle ( const TMatrix mat)
inline

Copy elements of 'mat', recycling elements of 'mat' if its size is smaller than current matrix.

Will only copy as many elements as necessary given _rows and _cols of current matrix.

90  {
91  if(_rows == mat._rows && _cols == mat._cols)
92  copy(mat);
93  else if(_val == NULL || _length == 0)
94  error("TMatrix::copy_recycle::matrix must be allocated before call\n");
95  else {
96  for(unsigned int i = 0; i < _rows; ++i)
97  for(unsigned int j = 0; j < _cols; ++j)
98  set(i, j, mat._val[ (i%mat._rows)*mat._cols + (j%mat._cols) ]); //mat.get( i%nrow, j%ncol )); _val[i*_cols + j]
99  }
100  }
void set(unsigned int i, unsigned int j, double val)
Sets element at row i and column j to value val.
Definition: tmatrix.h:102
int error(const char *str,...)
Definition: output.cc:78

References _cols, _rows, _val, and error().

Referenced by LCE_Selection_base::set_sel_model(), TProtoQuanti::setDominanceParameters(), TProtoQuanti::setEpistasisParameters(), TProtoQuanti::setMutationCorrelation(), TProtoQuanti::setMutationSigmaFromQuantiMutationVariance_no_pleio(), LCE_Breed_Disperse::setParameters(), TProtoBDMI::setParameters(), LCE_FileServicesNotifier::setSamplingParameters(), and LCE_Selection_base::setSelectionOffset().

+ Here is the caller graph for this function:

◆ divide()

void TMatrix::divide ( unsigned int  i,
unsigned int  j,
double  value 
)
inline

Divide an element of the matrix by a value.

316  {
317  if( i*j < _length)
318  _val[i*_cols + j] /= value;
319  else
320  error("TMatrix::divide overflow!\n");
321  }

References error().

Referenced by TTNeutralGenesSH::setAlleleTables().

+ Here is the caller graph for this function:

◆ get() [1/2]

double* TMatrix::get ( ) const
inline

Accessor to the whole array.

200 {return _val;}

◆ get() [2/2]

double TMatrix::get ( unsigned int  i,
unsigned int  j 
) const
inline

Accessor to element at row i and column j.

192  {
193  if( !((i+1)*(j+1) > _length) )
194  return _val[i*_cols + j];
195  else
196  fatal("TMatrix::get overflow!\n");
197  return 0;
198  }
void fatal(const char *str,...)
Definition: output.cc:99

References fatal().

Referenced by Metapop::buildPatchArray(), LCE_Selection_base::changeLocalOptima(), LCE_PhenotypeExpression::check_g_index_matrix(), LCE_Disperse_base::checkBackwardDispersalMatrix(), LCE_Disperse_base::checkForwardDispersalMatrix(), LCE_Patch_Extinction::do_remove(), LCE_Patch_Extinction::execute(), LCE_PhenotypeExpression::execute(), LCE_QuantiModifier::execute(), LCE_Breed_Disperse::exponentialGrowth(), TTNOhtaStats::FHwrite(), TTQFreqExtractor::FHwrite(), TTQOhtaStats::FHwrite(), TProtoQuanti::get_diallele_value(), TProtoQuanti::get_dominance(), LCE_PhenotypeExpression::get_env_cue_no_noise(), LCE_PhenotypeExpression::get_env_cue_noise(), TTQuanti_continuous_full_pleio_epistasis::get_epistatic_genotype(), TTQuanti_diallelic_full_pleio_epistasis::get_epistatic_genotype(), TTQuanti_continuous_no_pleio_epistasis::get_epistatic_genotype(), TTQuanti_diallelic_no_pleio_epistasis::get_epistatic_genotype(), TTQuanti_diallelic_bitstring_no_pleio_epistasis::get_epistatic_genotype(), TTQuanti_diallelic_bitstring_full_pleio_epistasis::get_epistatic_genotype(), LCE_Patch_Extinction::get_harvest_size(), TProtoQuanti::get_init_value(), TProtoQuanti::get_init_variance(), TProtoQuanti::get_trait_mutation_variance(), TTNeutralGenesSH::getCoa(), LCE_Breed_base::getFecundity(), LCE_Selection_base::getFitnessMultivariateDisruptive(), LCE_Selection_base::getFitnessMultivariateGaussian(), LCE_Selection_base::getFitnessMultivariateGaussian_VE(), LCE_Selection_base::getFitnessTruncation(), LCE_Selection_base::getFitnessUnivariateDisruptive(), LCE_Selection_base::getFitnessUnivariateGaussian(), LCE_Selection_base::getFitnessUnivariateGaussian_VE(), LCE_Selection_base::getFitnessUnivariateLinear(), LCE_Selection_base::getFitnessUnivariateQuadratic(), TTNeutralGenesSH::getFst_ij(), TProtoBDMI::getGenoFitnessDiplo(), TProtoBDMI::getGenoFitnessHaplo(), TTNeutralGenesSH::getGlobalAlleleFreq(), LCE_Breed_base::getMeanFecundity(), TProtoQuanti::getMutationEffectBivariateDiallelic(), TProtoQuanti::getMutationEffectBivariateGaussian(), TProtoQuanti::getMutationEffectBivariateGaussianLocSpec(), TProtoQuanti::getMutationEffectUnivariateGaussian(), TProtoQuanti::getMutationEffectUnivariateGaussianLocSpec(), TTNeutralGenesSH::getNeiGeneticDistance(), Metapop::getPatchCapacity(), FileServices::getSampledPop(), TTQuantiSH::getVaNoDominance(), TTQuantiSH::getVaWithDominance(), TTDispersal::init_sequence(), LCE_Breed_Wolbachia::inoculate_wolbachia(), LCE_Breed_Disperse::logisticGrowth(), TProtoQuanti::mutate_diallelic_pleio(), TProtoQuanti::mutate_diallelic_var_pleio(), LCE_Breed_base::NonWrightFisherPopulation(), LCE_Breed_Quanti::NonWrightFisherPopulation(), LCE_Breed_Disperse::numFemOffspring_colonizers(), LCE_Breed_Disperse::numMalOffspring_random_colonizers(), LCE_Resize::removeDesignatedPatch(), TProtoQuanti::set_gsl_mutation_matrix_from_sigma(), FileHandler::set_OccMatrix(), LCE_Selection_base::set_param_rate_of_change(), LCE_PhenotypeExpression::set_phenot_g1_evol(), LCE_PhenotypeExpression::set_phenot_g1_g2_evol(), LCE_PhenotypeExpression::set_phenot_g2_evol(), LCE_PhenotypeExpression::set_phenot_no_evol(), LCE_Selection_base::set_sel_model(), LCE_Selection_base::set_std_rate_of_change(), LCE_Disperse_base::setBasicLatticeMatrix(), TProtoQuanti::setContinuousMutationModel_full_pleio(), TProtoQuanti::setContinuousMutationModel_var_pleio(), TProtoQuanti::setDiallelicMutationModel(), TProtoQuanti::setDominanceParameters(), TProtoDeletMutations_bitstring::setEffectsFromInput(), LCE_Breed_base::setFecundity(), TTNeutralGenesSH::setFst_li(), TTNeutralGenesSH::setFstatWeirCockerham(), TTNeutralGenesSH::setFstatWeirCockerham_MS(), TTNeutralGenesSH::setFstMatrix(), TTProtoWithMap::setGeneticMapParameters(), TProtoQuanti::setHeritabilityParams(), TTNeutralGenesSH::setHt(), TTNeutralGenesSH::setHt2(), LCE_PhenotypeExpression::setIndLiability(), LCE_PhenotypeExpression::setIndLiability_evolving(), LCE_PhenotypeExpression::setIndLiability_evolving_sigmoid(), LCE_PhenotypeExpression::setIndLiability_sigmoid(), LCE_Disperse_base::setLatticeAbsorbingMatrix(), LCE_Disperse_base::setLatticeReflectingMatrix(), LCE_Disperse_base::setLatticeTorrusMatrix(), TTNeutralGenesSH::setLociDivCounter(), TProtoQuanti::setMutationModel_no_pleio(), TProtoQuanti::setMutationModel_var_pleio(), TProtoQuanti::setMutationSigmaFromQuantiMutationVariance(), TProtoQuanti::setMutationSigmaFromQuantiMutationVariance_no_pleio(), TTProtoWithMap::setNumLociPerChromosome(), LCE_StatServiceNotifier::setOccurence(), LCE_Breed_Disperse::setParameters(), LCE_Resize::setParameters(), LCE_PhenotypeExpression::setParameters(), TProtoBDMI::setParameters(), Metapop::setPatchCapacities(), LCE_Init_BDMI::setPatchFreq(), LCE_Selection_base::setSelectionMatrix(), LCE_Selection_base::setSelectionOffset(), LCE_Selection_base::setSelectTraitMapping(), setSpatialMatrix(), LCE_Init_BDMI::setSpatialPattern(), TProtoQuanti::setTraitAndLocusTables_no_pleio(), TProtoBDMI::showGenoTable(), ParamsParser::sym_matrix(), transpose(), LCE_Resize::updatePatchCapacities(), Metapop::updatePatchState(), and TTNeutralGenesFH::write_varcompWC().

◆ get_dims()

unsigned int TMatrix::get_dims ( unsigned int *  dims) const
inline

Accessor to the matrix dimensions.

Parameters
dimsan array of at least 2 elements to store the row [0] and column [1] numbers. May be NULL.
Returns
the total size of the matrix
206  {
207  if(dims != NULL) { dims[0] = _rows; dims[1] = _cols; }
208  return _length;
209  }

◆ getColumnView()

void TMatrix::getColumnView ( unsigned int  col,
unsigned int  n,
double *  array 
)
inline

Gives access to a column of the matrix.

Parameters
colindex of col to view
nsize of the storing array passed, must be equal to no. of rows
arrayarray where the column values will be stored
224  {
225  if(col > _cols-1) {
226  error("TMatrix::getColumnView: not that many columns in matrix\n");
227  return;
228  }
229  if(n != _rows) {
230  error("TMatrix::getColumnView: array size not equal to number of rows in matrix\n");
231  return;
232  }
233  for(unsigned int i = 0; i < _rows; ++i)
234  array[i] = _val[i*_cols + col];
235  }

References error().

◆ getNbCols()

◆ getNbRows()

◆ getRowView()

void TMatrix::getRowView ( unsigned int  row,
unsigned int  n,
double *  array 
)
inline

Gives access to a row of the matrix.

Parameters
rowindex of row to view
nsize of the storing array passed, must be equal to no. of columns
arrayarray where the row values will be stored
242  {
243  if(row > _rows-1) {
244  error("TMatrix::getRowView: not that many rows in matrix\n");
245  return;
246  }
247  if(n != _cols) {
248  error("TMatrix::getRowView: array size not equal to number of columns in matrix\n");
249  return;
250  }
251  for(unsigned int i = 0, stride = row*_cols; i < _cols; ++i)
252  array[i] = _val[stride + i];
253  }

References error().

Referenced by LCE_QuantiInit::execute(), LCE_Init_BDMI::execute(), and LCE_NtrlInit::execute().

+ Here is the caller graph for this function:

◆ getValArray()

double* TMatrix::getValArray ( ) const
inline
201 {return _val;}

Referenced by FileHandler::set_OccMatrix().

+ Here is the caller graph for this function:

◆ length()

◆ matrix_increment()

void TMatrix::matrix_increment ( double  value)
inline

Adds a value to all elements in a matrix.

264  {
265  for(unsigned int i = 0; i < _rows; ++i){
266  for(unsigned int j = 0; j < _cols; ++j){
267  plus(i,j,value);
268  }
269  }
270  }
void plus(unsigned int i, unsigned int j, double value)
Adds a value to an element of the matrix.
Definition: tmatrix.h:255

Referenced by LCE_FileServicesNotifier::setSamplingParameters().

+ Here is the caller graph for this function:

◆ minus()

void TMatrix::minus ( unsigned int  i,
unsigned int  j,
double  value 
)
inline

Substracts a value from an element of the matrix.

282  {
283  if( i*j < _length)
284  _val[i*_cols + j] -= value;
285  else
286  error("TMatrix::minus overflow!\n");
287  }

References error().

Referenced by LCE_PhenotypeExpression::check_g_index_matrix().

+ Here is the caller graph for this function:

◆ multi()

void TMatrix::multi ( unsigned int  i,
unsigned int  j,
double  value 
)
inline

Multiply an element of the matrix by a value.

299  {
300  if( i*j < _length)
301  _val[i*_cols + j] *= value;
302  else
303  error("TMatrix::multi overflow!\n");
304  }

References error().

Referenced by LCE_Selection_base::set_std_rate_of_change().

+ Here is the caller graph for this function:

◆ ncols()

◆ nrows()

◆ plus()

void TMatrix::plus ( unsigned int  i,
unsigned int  j,
double  value 
)
inline

Adds a value to an element of the matrix.

256  {
257  if( i*j < _length)
258  _val[i*_cols + j] += value;
259  else
260  error("TMatrix::plus overflow!\n");
261  }

References error().

Referenced by LCE_Selection_base::changeLocalOptima(), LCE_PhenotypeExpression::execute(), TTNeutralGenesSH::setAlleleTables(), and LCE_Disperse_base::setLatticeAbsorbingMatrix().

+ Here is the caller graph for this function:

◆ reset() [1/4]

void TMatrix::reset ( )
inline

Reset members to zero state.

183  {
184  _rows = 0;
185  _cols = 0;
186  _length = 0;
187  if(_val != NULL) delete [] _val;
188  _val = NULL;
189  }

◆ reset() [2/4]

void TMatrix::reset ( unsigned int  rows,
unsigned int  cols 
)
inline

Re-allocate the existing matrix with assigned rows and cols dimensions and all elements to 0.

160  {
161  _length = rows * cols;
162  if(_length == 0) error("TMatrix::attempt to reset a matrix with size = 0!\n");
163  if(_val != NULL) delete [] _val;
164  _val = new double [_length];
165  memset(_val, 0, _length*sizeof(double));
166  _rows = rows; _cols = cols;
167  }

References error().

Referenced by LCE_Disperse_base::allocateDispMatrix(), TTNeutralGenesSH::allocateTables(), Param::parse_matrix(), LCE_PhenotypeExpression::set_env_cue(), LCE_PhenotypeExpression::set_g_value_matrix(), TProtoQuanti::set_init_values(), LCE_Selection_base::set_local_optima(), LCE_Patch_Extinction::set_matrix_param(), FileHandler::set_OccMatrix(), LCE_Selection_base::set_param_rate_of_change(), LCE_Selection_base::set_sel_model(), LCE_Selection_base::set_std_rate_of_change(), TProtoQuanti::setContinuousMutationModel_full_pleio(), TProtoQuanti::setContinuousMutationModel_var_pleio(), TProtoQuanti::setDiallelicMutationModel(), TProtoQuanti::setDominanceParameters(), TProtoQuanti::setEpistasisParameters(), LCE_Breed_base::setFecundity(), TTNeutralGenesSH::setFstMatrix(), LCE_Disperse_base::setIndentityDispMatrix(), TProtoQuanti::setInitialValuesParams(), TProtoQuanti::setMutationCorrelation(), TProtoQuanti::setMutationModel_no_pleio(), TProtoQuanti::setMutationSigmaFromQuantiMutationVariance(), TProtoQuanti::setMutationSigmaFromQuantiMutationVariance_no_pleio(), TTNeutralGenesSH::setNeiGeneticDistance(), LCE_Breed_Disperse::setParameters(), LCE_PhenotypeExpression::setParameters(), LCE_QuantiModifier::setParameters(), LCE_FileServicesNotifier::setParameters(), TProtoBDMI::setParameters(), LCE_Init_BDMI::setParameters(), Metapop::setPatchCapacities(), LCE_FileServicesNotifier::setSamplingParameters(), LCE_Selection_base::setSelectionMatrix(), LCE_Selection_base::setSelectionOffset(), setSpatialMatrix(), and LCE_Resize::updateParameters().

◆ reset() [3/4]

void TMatrix::reset ( unsigned int  rows,
unsigned int  cols,
const double *  array 
)
inline

Reset the existing matrix to the new dimensions and copies the array, which has to be of the same total length.

176  {
177  reset(rows, cols);
178  memcpy(_val, array, _length * sizeof(double));
179  }
void reset()
Reset members to zero state.
Definition: tmatrix.h:182

◆ reset() [4/4]

void TMatrix::reset ( unsigned int  rows,
unsigned int  cols,
double  value 
)
inline

Reset the existing matrix to the new dimensions and copies the value to all elements.

170  {
171  reset(rows, cols);
172  assign(value);
173  }
void assign(double val)
Assigns a value to all element of the matrix.
Definition: tmatrix.h:154

◆ rowSum()

double TMatrix::rowSum ( unsigned int  row)
inline

Sum all elements in a row.

354  {
355  assert(row < _rows); // has to be [0, _rows-1]
356  double sum = 0;
357  for (unsigned int i = 0; i < _cols; ++i) {
358  sum += _val[row*_cols + i];
359  }
360  return sum;
361  }

Referenced by LCE_Disperse_base::setLatticeReflectingMatrix(), and TProtoQuanti::setMutationModel_no_pleio().

+ Here is the caller graph for this function:

◆ set()

void TMatrix::set ( unsigned int  i,
unsigned int  j,
double  val 
)
inline

◆ set_col() [1/2]

void TMatrix::set_col ( unsigned int  i,
double  val 
)
inline

Sets element at column i to value val.

132  {
133  if( i < _cols)
134  for(unsigned int j = 0; j < _rows; ++j)
135  _val[j*_cols + i] = val;
136  else
137  error("TMatrix::set_col overflow, i > num cols!\n");
138  }

References error().

Referenced by TProtoQuanti::setDiallelicMutationModel().

+ Here is the caller graph for this function:

◆ set_col() [2/2]

void TMatrix::set_col ( unsigned int  i,
vector< double >  vec 
)
inline

Sets element at column i to values stored in vector vec.

141  {
142 
143  if(vec.size() < _rows)
144  fatal("TMatrix::set_col copy from vector too small to fit\n");
145 
146  if( i < _cols)
147  for(unsigned int j = 0; j < _rows; ++j)
148  _val[j*_cols + i] = vec[j];
149  else
150  error("TMatrix::set_col overflow, i > num cols!\n");
151  }

References error(), and fatal().

◆ set_row() [1/2]

void TMatrix::set_row ( unsigned int  i,
double  val 
)
inline

Sets all elements at row i to value val.

110  {
111  if( i < _rows)
112  for(unsigned int j = 0, stride = i*_cols; j < _cols; ++j)
113  _val[stride + j] = val;
114  else
115  error("TMatrix::set_row overflow, i > num rows!\n");
116  }

References error().

Referenced by TProtoQuanti::setMutationSigmaFromQuantiMutationVariance(), and LCE_Breed_Disperse::setParameters().

+ Here is the caller graph for this function:

◆ set_row() [2/2]

void TMatrix::set_row ( unsigned int  i,
vector< double >  vec 
)
inline

Sets elements at row i to values stored in vector vec.

119  {
120 
121  if(vec.size() < _cols)
122  fatal("TMatrix::set_row copy from vector too small to fit\n");
123 
124  if( i < _rows)
125  for(unsigned int j = 0, stride = i*_cols; j < _cols; ++j)
126  _val[stride + j] = vec[j];
127  else
128  error("TMatrix::set_row overflow, i > num rows!\n");
129  }

References error(), and fatal().

◆ show_up()

void TMatrix::show_up ( )
inline
364  {
365  message("TMatrix dimensions: \nrows = %i, columns = %i, length = %i\n",_rows,_cols, _length);
366  for(unsigned int i = 0; i < _rows; i++) {
367  for(unsigned int j = 0; j < _cols; j++)
368  message("%.3f ",_val[i*_cols + j]);
369  message("\n");
370  }
371  }
void message(const char *message,...)
Definition: output.cc:39

References message().

Referenced by TProtoQuanti::setContinuousMutationModel_full_pleio(), TProtoQuanti::setMutationSigmaFromQuantiMutationVariance(), TProtoQuanti::setMutationSigmaFromQuantiMutationVariance_no_pleio(), LCE_Disperse_base::setReducedDispMatrix(), and Metapop::show_up().

+ Here is the caller graph for this function:

◆ sweep_divide()

void TMatrix::sweep_divide ( double  value)
inline

Divide all elements of the matrix by a value.

324  {
325  for(unsigned int i = 0; i < _rows; ++i){
326  for(unsigned int j = 0; j < _cols; ++j){
327  divide(i,j,value);
328  }
329  }
330  }
void divide(unsigned int i, unsigned int j, double value)
Divide an element of the matrix by a value.
Definition: tmatrix.h:315

◆ sweep_minus()

void TMatrix::sweep_minus ( double  value)
inline

Substracts a value to all elements in a matrix.

290  {
291  for(unsigned int i = 0; i < _rows; ++i){
292  for(unsigned int j = 0; j < _cols; ++j){
293  minus(i,j,value);
294  }
295  }
296  }
void minus(unsigned int i, unsigned int j, double value)
Substracts a value from an element of the matrix.
Definition: tmatrix.h:281

◆ sweep_multiply()

void TMatrix::sweep_multiply ( double  value)
inline

multiply each element by a value.

307  {
308  for(unsigned int i = 0; i < _rows; ++i){
309  for(unsigned int j = 0; j < _cols; ++j){
310  multi(i,j,value);
311  }
312  }
313  }
void multi(unsigned int i, unsigned int j, double value)
Multiply an element of the matrix by a value.
Definition: tmatrix.h:298

◆ sweep_plus()

void TMatrix::sweep_plus ( double  value)
inline

Adds a value to all elements in a matrix.

273  {
274  for(unsigned int i = 0; i < _rows; ++i){
275  for(unsigned int j = 0; j < _cols; ++j){
276  plus(i,j,value);
277  }
278  }
279  }

◆ to_string()

string TMatrix::to_string ( )
inline

Writes the matrix into a string in Nemo's matrix input format.

374  {
375  ostringstream OUT;
376 
377  OUT << "{";
378  for(unsigned int i = 0; i < _rows; i++) {
379  OUT<<"{";
380  for(unsigned int j = 0; j < _cols-1; j++) {
381  OUT<<_val[i*_cols + j]<<",";
382  }
383  OUT<<_val[i*_cols + _cols-1]<<"}";
384  }
385  OUT << "}";
386 
387  return OUT.str();
388  }

Referenced by LCE_Selection_base::set_std_rate_of_change(), and ParamsParser::sym_matrix().

+ Here is the caller graph for this function:

◆ transpose()

void TMatrix::transpose ( )
inline

Transpose the matrix, swaps columns for rows.

333  {
334  TMatrix tmp(_cols, _rows);
335 
336  for(unsigned int i = 0; i < _rows; i++)
337  for(unsigned int j = 0; j < _cols; j++)
338  tmp.set(j, i, get(i, j));
339 
340  reset(_cols, _rows, tmp.get());
341  }
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49
double * get() const
Accessor to the whole array.
Definition: tmatrix.h:200

References get(), and set().

Referenced by LCE_Disperse_base::setLatticeReflectingMatrix(), and LCE_Disperse_base::setSteppingStone1DMatrix().

+ Here is the caller graph for this function:

Member Data Documentation

◆ _cols

unsigned int TMatrix::_cols
private

Referenced by copy(), and copy_recycle().

◆ _length

unsigned int TMatrix::_length
private

◆ _rows

unsigned int TMatrix::_rows
private

Referenced by copy(), and copy_recycle().

◆ _val

double* TMatrix::_val
private

Referenced by copy(), and copy_recycle().


The documentation for this class was generated from the following file:

Generated for Nemo v2.4.0 by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR