35 #ifndef OPENMS_DATASTRUCTURES_MATRIX_H 
   36 #define OPENMS_DATASTRUCTURES_MATRIX_H 
   44 #include <gsl/gsl_matrix.h> 
   45 #include <gsl/gsl_vector.h> 
   46 #include <gsl/gsl_linalg.h> 
   78   template <
typename Value>
 
   80     protected std::vector<Value>
 
   83     typedef std::vector<Value> 
Base;
 
  135       Base(rows * cols, value),
 
  148       Base::operator=(rhs);
 
  171       return Base::operator[](
index(i, j));
 
  176       return Base::operator[](
index(i, j));
 
  181       Base::operator[](
index(i, j)) = value;
 
  193         values[j] = Base::operator[](
index(i, j));
 
  207         values[j] = Base::operator[](
index(j, i));
 
  235     using Base::capacity;
 
  236     using Base::max_size;
 
  256       rows_ = size_pair.first;
 
  257       cols_ = size_pair.second;
 
  300       return std::pair<SizeType, SizeType>(index / 
cols_, index % 
cols_);
 
  312       return index % 
cols_;
 
  325       return index / 
cols_;
 
  336                           "Matrices have different row sizes.");
 
  338                           "Matrices have different column sizes.");
 
  350                           "Matrices have different row sizes.");
 
  352                           "Matrices have different column sizes.");
 
  357     template <
int ROWS, 
int COLS>
 
  379       gsl_matrix* m_ptr = gsl_matrix_alloc(
rows_, 
cols_);
 
  385           gsl_matrix_set(m_ptr, i, j, (
double) (*
this)(i, j));
 
  412   template <
typename Value>
 
  413   std::ostream& operator<<(std::ostream& os, const Matrix<Value>& matrix)
 
  416     for (size_type i = 0; i < matrix.rows(); ++i)
 
  418       for (size_type j = 0; j < matrix.cols(); ++j)
 
  420         os << std::setprecision(6) << std::setw(6) << matrix(i, j) << 
' ';
 
  429 #endif // OPENMS_DATASTRUCTURES_MATRIX_H 
Base::value_type value_type
Definition: Matrix.h:102
std::pair< Size, Size > sizePair() const 
Definition: Matrix.h:273
Base ContainerType
Definition: Matrix.h:109
const_iterator ConstIterator
Definition: Matrix.h:113
allocator_type AllocatorType
Definition: Matrix.h:123
value_type ValueType
Definition: Matrix.h:121
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:295
SizeType rowIndex(SizeType index) const 
Calculate the row from an index into the underlying vector. Note that Matrix uses the (row...
Definition: Matrix.h:319
Base::const_reference const_reference
Definition: Matrix.h:99
const_reference ConstReference
Definition: Matrix.h:118
Int overflow exception. 
Definition: Exception.h:255
iterator Iterator
Definition: Matrix.h:115
#define OPENMS_PRECONDITION(condition, message)
Precondition macro. 
Definition: Macros.h:107
Base::pointer pointer
Definition: Matrix.h:100
SizeType colIndex(SizeType index) const 
Calculate the column from an index into the underlying vector. Note that Matrix uses the (row...
Definition: Matrix.h:307
bool operator==(Matrix const &rhs) const 
Equality comparator. 
Definition: Matrix.h:333
pointer Pointer
Definition: Matrix.h:119
gsl_matrix * toGslMatrix()
create gsl_matrix* 
Definition: Matrix.h:377
container_type col(size_type const i) const 
Return the i-th column of the matrix as a vector. 
Definition: Matrix.h:199
reverse_iterator ReverseIterator
Definition: Matrix.h:116
Base::difference_type difference_type
Definition: Matrix.h:91
size_type SizeType
Definition: Matrix.h:111
void resize(size_type i, size_type j, value_type value=value_type())
Definition: Matrix.h:247
~Matrix()
Definition: Matrix.h:154
const_reference getValue(size_type const i, size_type const j) const 
Definition: Matrix.h:169
container_type row(size_type const i) const 
Return the i-th row of the matrix as a vector. 
Definition: Matrix.h:185
Base::const_iterator const_iterator
Definition: Matrix.h:94
Matrix(const SizeType rows, const SizeType cols, ValueType value=ValueType())
Definition: Matrix.h:134
Base::iterator iterator
Definition: Matrix.h:96
bool operator<(Matrix const &rhs) const 
Less-than comparator. Comparison is done lexicographically: first by row, then by column...
Definition: Matrix.h:347
std::vector< Value > Base
Definition: Matrix.h:83
void resize(std::pair< Size, Size > const &size_pair, value_type value=value_type())
Definition: Matrix.h:254
Matrix & operator=(const Matrix &rhs)
Definition: Matrix.h:146
reference Reference
Definition: Matrix.h:120
SizeType cols_
Number of columns (width of a row) 
Definition: Matrix.h:399
SizeType rows() const 
Number of rows. 
Definition: Matrix.h:262
SizeType cols() const 
Number of columns. 
Definition: Matrix.h:268
Base::reverse_iterator reverse_iterator
Definition: Matrix.h:97
difference_type DifferenceType
Definition: Matrix.h:110
Base::reference reference
Definition: Matrix.h:101
Base::allocator_type allocator_type
Definition: Matrix.h:104
const_reverse_iterator ConstReverseIterator
Definition: Matrix.h:114
reference operator()(size_type const i, size_type const j)
Definition: Matrix.h:164
Base::size_type size_type
Definition: Matrix.h:92
size_t Size
Size type e.g. used as variable which can hold result of size() 
Definition: Types.h:144
Base container_type
Definition: Matrix.h:89
void setMatrix(const ValueType matrix[ROWS][COLS])
set matrix to 2D arrays values 
Definition: Matrix.h:358
void setValue(size_type const i, size_type const j, value_type value)
Definition: Matrix.h:179
Base::const_reverse_iterator const_reverse_iterator
Definition: Matrix.h:95
reference getValue(size_type const i, size_type const j)
Definition: Matrix.h:174
Matrix(const Matrix &source)
Definition: Matrix.h:140
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:282
Matrix()
Definition: Matrix.h:128
void clear()
Definition: Matrix.h:240
A two-dimensional matrix. Similar to std::vector, but uses a binary operator(,) for element access...
Definition: Matrix.h:79
const_reference operator()(size_type const i, size_type const j) const 
Definition: Matrix.h:159
SizeType rows_
Number of rows (height of a column) 
Definition: Matrix.h:397