Nemo  2.4.2
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
57 : _rows(0), _cols(0), _length(0), _val(0) { }
unsigned int _cols
Definition: tmatrix.h:51
unsigned int _rows
Definition: tmatrix.h:51
double * _val
Definition: tmatrix.h:53
unsigned int _length
Definition: tmatrix.h:51

◆ TMatrix() [2/3]

TMatrix::TMatrix ( const TMatrix mat)
inline

copy constructor.

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

◆ TMatrix() [3/3]

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

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

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

◆ ~TMatrix()

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

Member Function Documentation

◆ assign()

◆ colSum()

double TMatrix::colSum ( unsigned int  col)
inline

Sum all elements in a column.

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

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.

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

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.

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

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.

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

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.

199 {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.

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

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
205  {
206  if(dims != NULL) { dims[0] = _rows; dims[1] = _cols; }
207  return _length;
208  }

◆ 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
223  {
224  if(col > _cols-1) {
225  error("TMatrix::getColumnView: not that many columns in matrix\n");
226  return;
227  }
228  if(n != _rows) {
229  error("TMatrix::getColumnView: array size not equal to number of rows in matrix\n");
230  return;
231  }
232  for(unsigned int i = 0; i < _rows; ++i)
233  array[i] = _val[i*_cols + col];
234  }

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
241  {
242  if(row > _rows-1) {
243  error("TMatrix::getRowView: not that many rows in matrix\n");
244  return;
245  }
246  if(n != _cols) {
247  error("TMatrix::getRowView: array size not equal to number of columns in matrix\n");
248  return;
249  }
250  for(unsigned int i = 0, stride = row*_cols; i < _cols; ++i)
251  array[i] = _val[stride + i];
252  }

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
200 {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.

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

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.

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

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.

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

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.

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

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.

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

◆ 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.

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

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.

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

◆ 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.

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

◆ rowSum()

double TMatrix::rowSum ( unsigned int  row)
inline

Sum all elements in a row.

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

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.

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

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.

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

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.

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

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.

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

References error(), and fatal().

◆ show_up()

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

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.

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

◆ sweep_minus()

void TMatrix::sweep_minus ( double  value)
inline

Substracts a value to all elements in a matrix.

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

◆ sweep_multiply()

void TMatrix::sweep_multiply ( double  value)
inline

multiply each element by a value.

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

◆ sweep_plus()

void TMatrix::sweep_plus ( double  value)
inline

Adds a value to all elements in a matrix.

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

◆ to_string()

string TMatrix::to_string ( )
inline

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

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

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.

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

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.2 by  doxygen 1.9.1

Catalogued on GSR