35 #ifndef OPENMS_DATASTRUCTURES_MATRIX_H 36 #define OPENMS_DATASTRUCTURES_MATRIX_H 75 template <
typename Value>
77 protected std::vector<Value>
80 typedef std::vector<Value>
Base;
132 Base(rows * cols, value),
145 Base::operator=(rhs);
156 const_reference
operator()(size_type
const i, size_type
const j)
const 166 const_reference
getValue(size_type
const i, size_type
const j)
const 168 return Base::operator[](
index(i, j));
171 reference
getValue(size_type
const i, size_type
const j)
173 return Base::operator[](
index(i, j));
176 void setValue(size_type
const i, size_type
const j, value_type value)
178 Base::operator[](
index(i, j)) = value;
182 container_type
row(size_type
const i)
const 187 container_type values(
cols_);
188 for (size_type j = 0; j <
cols_; j++)
190 values[j] = Base::operator[](
index(i, j));
196 container_type
col(size_type
const i)
const 201 container_type values(
rows_);
202 for (size_type j = 0; j <
rows_; j++)
204 values[j] = Base::operator[](
index(j, i));
232 using Base::capacity;
233 using Base::max_size;
253 rows_ = size_pair.first;
254 cols_ = size_pair.second;
297 return std::pair<SizeType, SizeType>(index /
cols_, index %
cols_);
309 return index %
cols_;
322 return index /
cols_;
333 "Matrices have different row sizes.");
335 "Matrices have different column sizes.");
347 "Matrices have different row sizes.");
349 "Matrices have different column sizes.");
354 template <
int ROWS,
int COLS>
358 for (SizeType i = 0; i < this->
rows_; ++i)
360 for (SizeType j = 0; j < this->
cols_; ++j)
384 template <
typename Value>
385 std::ostream& operator<<(std::ostream& os, const Matrix<Value>& matrix)
388 for (size_type i = 0; i < matrix.rows(); ++i)
390 for (size_type j = 0; j < matrix.cols(); ++j)
392 os << std::setprecision(6) << std::setw(6) << matrix(i, j) <<
' ';
401 #endif // OPENMS_DATASTRUCTURES_MATRIX_H Base::value_type value_type
Definition: Matrix.h:99
Base ContainerType
Definition: Matrix.h:106
const_iterator ConstIterator
Definition: Matrix.h:110
allocator_type AllocatorType
Definition: Matrix.h:120
value_type ValueType
Definition: Matrix.h:118
bool operator==(Matrix const &rhs) const
Equality comparator.
Definition: Matrix.h:330
Base::const_reference const_reference
Definition: Matrix.h:96
std::pair< Size, Size > const indexPair(Size index) const
Calculate the row and column from an index into the underlying vector. Note that Matrix uses the (row...
Definition: Matrix.h:292
const_reference ConstReference
Definition: Matrix.h:115
Int overflow exception.
Definition: Exception.h:255
iterator Iterator
Definition: Matrix.h:112
#define OPENMS_PRECONDITION(condition, message)
Precondition macro.
Definition: openms/include/OpenMS/CONCEPT/Macros.h:107
Base::pointer pointer
Definition: Matrix.h:97
pointer Pointer
Definition: Matrix.h:116
reverse_iterator ReverseIterator
Definition: Matrix.h:113
Base::difference_type difference_type
Definition: Matrix.h:88
size_type SizeType
Definition: Matrix.h:108
const_reference operator()(size_type const i, size_type const j) const
Definition: Matrix.h:156
void resize(size_type i, size_type j, value_type value=value_type())
Definition: Matrix.h:244
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
~Matrix()
Definition: Matrix.h:151
bool operator<(Matrix const &rhs) const
Less-than comparator. Comparison is done lexicographically: first by row, then by column...
Definition: Matrix.h:344
Base::const_iterator const_iterator
Definition: Matrix.h:91
Matrix(const SizeType rows, const SizeType cols, ValueType value=ValueType())
Definition: Matrix.h:131
Base::iterator iterator
Definition: Matrix.h:93
std::vector< Value > Base
Definition: Matrix.h:80
container_type col(size_type const i) const
Return the i-th column of the matrix as a vector.
Definition: Matrix.h:196
void resize(std::pair< Size, Size > const &size_pair, value_type value=value_type())
Definition: Matrix.h:251
SizeType colIndex(SizeType index) const
Calculate the column from an index into the underlying vector. Note that Matrix uses the (row...
Definition: Matrix.h:304
std::pair< Size, Size > sizePair() const
Definition: Matrix.h:270
Matrix & operator=(const Matrix &rhs)
Definition: Matrix.h:143
reference Reference
Definition: Matrix.h:117
container_type row(size_type const i) const
Return the i-th row of the matrix as a vector.
Definition: Matrix.h:182
SizeType cols_
Number of columns (width of a row)
Definition: Matrix.h:374
Base::reverse_iterator reverse_iterator
Definition: Matrix.h:94
difference_type DifferenceType
Definition: Matrix.h:107
Base::reference reference
Definition: Matrix.h:98
Base::allocator_type allocator_type
Definition: Matrix.h:101
const_reverse_iterator ConstReverseIterator
Definition: Matrix.h:111
reference operator()(size_type const i, size_type const j)
Definition: Matrix.h:161
SizeType cols() const
Number of columns.
Definition: Matrix.h:265
Base::size_type size_type
Definition: Matrix.h:89
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:128
Base container_type
Definition: Matrix.h:86
SizeType rowIndex(SizeType index) const
Calculate the row from an index into the underlying vector. Note that Matrix uses the (row...
Definition: Matrix.h:316
void setMatrix(const ValueType matrix[ROWS][COLS])
set matrix to 2D arrays values
Definition: Matrix.h:355
void setValue(size_type const i, size_type const j, value_type value)
Definition: Matrix.h:176
Base::const_reverse_iterator const_reverse_iterator
Definition: Matrix.h:92
SizeType rows() const
Number of rows.
Definition: Matrix.h:259
const_reference getValue(size_type const i, size_type const j) const
Definition: Matrix.h:166
reference getValue(size_type const i, size_type const j)
Definition: Matrix.h:171
SizeType const index(SizeType row, SizeType col) const
Calculate the index into the underlying vector from row and column. Note that Matrix uses the (row...
Definition: Matrix.h:279
Matrix(const Matrix &source)
Definition: Matrix.h:137
Matrix()
Definition: Matrix.h:125
void clear()
Definition: Matrix.h:237
A two-dimensional matrix. Similar to std::vector, but uses a binary operator(,) for element access...
Definition: IsobaricQuantitationMethod.h:50
SizeType rows_
Number of rows (height of a column)
Definition: Matrix.h:372