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);
168 return Base::operator[](
index(i, j));
173 return Base::operator[](
index(i, j));
178 Base::operator[](
index(i, j)) = value;
190 values[j] = Base::operator[](
index(i, 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>
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
std::pair< Size, Size > sizePair() const
Definition: Matrix.h:270
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
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
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
Base::const_reference const_reference
Definition: Matrix.h:96
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
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
bool operator==(Matrix const &rhs) const
Equality comparator.
Definition: Matrix.h:330
pointer Pointer
Definition: Matrix.h:116
container_type col(size_type const i) const
Return the i-th column of the matrix as a vector.
Definition: Matrix.h:196
reverse_iterator ReverseIterator
Definition: Matrix.h:113
Base::difference_type difference_type
Definition: Matrix.h:88
size_type SizeType
Definition: Matrix.h:108
void resize(size_type i, size_type j, value_type value=value_type())
Definition: Matrix.h:244
~Matrix()
Definition: Matrix.h:151
const_reference getValue(size_type const i, size_type const j) const
Definition: Matrix.h:166
container_type row(size_type const i) const
Return the i-th row of the matrix as a vector.
Definition: Matrix.h:182
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
bool operator<(Matrix const &rhs) const
Less-than comparator. Comparison is done lexicographically: first by row, then by column...
Definition: Matrix.h:344
std::vector< Value > Base
Definition: Matrix.h:80
void resize(std::pair< Size, Size > const &size_pair, value_type value=value_type())
Definition: Matrix.h:251
Matrix & operator=(const Matrix &rhs)
Definition: Matrix.h:143
reference Reference
Definition: Matrix.h:117
SizeType cols_
Number of columns (width of a row)
Definition: Matrix.h:374
SizeType rows() const
Number of rows.
Definition: Matrix.h:259
SizeType cols() const
Number of columns.
Definition: Matrix.h:265
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
Base::size_type size_type
Definition: Matrix.h:89
Base container_type
Definition: Matrix.h:86
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
reference getValue(size_type const i, size_type const j)
Definition: Matrix.h:171
Matrix(const Matrix &source)
Definition: Matrix.h:137
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()
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
const_reference operator()(size_type const i, size_type const j) const
Definition: Matrix.h:156
SizeType rows_
Number of rows (height of a column)
Definition: Matrix.h:372