GEDLIB  1.0
matrix.hpp
Go to the documentation of this file.
1 /***************************************************************************
2 * *
3 * Copyright (C) 2018 by David B. Blumenthal *
4 * *
5 * This file is part of GEDLIB. *
6 * *
7 * GEDLIB is free software: you can redistribute it and/or modify it *
8 * under the terms of the GNU Lesser General Public License as published *
9 * by the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * GEDLIB is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU Lesser General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with GEDLIB. If not, see <http://www.gnu.org/licenses/>. *
19 * *
20 ***************************************************************************/
21 
27 #ifndef SRC_ENV_MATRIX_HPP_
28 #define SRC_ENV_MATRIX_HPP_
29 
30 #include "common_types.hpp"
31 
32 namespace ged {
33 
37 template<class ScalarT>
38 class Matrix {
39 
40 public:
44  Matrix();
45 
52  Matrix(std::size_t num_rows, std::size_t num_cols, ScalarT val = 0);
53 
58  Matrix(const Matrix & matrix);
59 
64  void operator=(const Matrix & matrix);
65 
70  void swap(Matrix& matrix);
71 
78  const ScalarT & operator() (std::size_t row, std::size_t col) const;
79 
86  ScalarT & operator() (std::size_t row, std::size_t col);
87 
88 
93  ScalarT * data();
94 
99  const ScalarT * data() const;
100 
101 
106  std::size_t num_rows() const;
107 
112  std::size_t num_cols() const;
113 
119  void resize(std::size_t num_rows, std::size_t num_cols);
120 
124  void set_to_val(const ScalarT & val);
125 
129  void power(std::size_t n);
130 
134  ScalarT max() const;
135 
139  ScalarT min() const;
140 
144  void transpose();
145 
149  Matrix<ScalarT> transposed() const;
150 
154  Matrix<ScalarT> & operator*=(const ScalarT & scalar);
155 
159  Matrix<ScalarT> & operator+=(const Matrix<ScalarT> & matrix);
160 
164  Matrix<ScalarT> & operator-=(const Matrix<ScalarT> & matrix);
165 
169  Matrix<ScalarT> operator*(const ScalarT & scalar) const;
170 
174  Matrix<ScalarT> operator+(const Matrix<ScalarT> & matrix) const;
175 
179  Matrix<ScalarT> operator-(const Matrix<ScalarT> & matrix) const;
180 
184  Eigen::Matrix<ScalarT, Eigen::Dynamic, Eigen::Dynamic> & matrix();
185 
189  const Eigen::Matrix<ScalarT, Eigen::Dynamic, Eigen::Dynamic> & matrix() const;
190 
191 private:
192  Eigen::Matrix<ScalarT, Eigen::Dynamic, Eigen::Dynamic> matrix_;
193 
194 };
195 
200 
205 
213 template<typename ScalarT>
214 std::ostream & operator<<(std::ostream & os, const Matrix<ScalarT> & matrix);
215 
216 }
217 
218 #include "matrix.ipp"
219 
220 #endif /* SRC_ENV_MATRIX_HPP_ */
A matrix class with basic functionality.
Definition: matrix.hpp:38
void power(std::size_t n)
Takes the matrix to the power of n.
Definition: matrix.ipp:117
ScalarT max() const
Returns the maximal coefficient.
Definition: matrix.ipp:163
void resize(std::size_t num_rows, std::size_t num_cols)
Resizes the matrix.
Definition: matrix.ipp:92
void swap(Matrix &matrix)
Swaps the matrix with another matrix.
Definition: matrix.ipp:156
ged::Matrix class definition.
Matrix< ScalarT > operator-(const Matrix< ScalarT > &matrix) const
Matrix-matrix addition.
Definition: matrix.ipp:219
Matrix< ScalarT > operator*(const ScalarT &scalar) const
Matrix-scalar multiplication.
Definition: matrix.ipp:201
Matrix< ScalarT > operator+(const Matrix< ScalarT > &matrix) const
Matrix-matrix addition.
Definition: matrix.ipp:210
Matrix< ScalarT > & operator*=(const ScalarT &scalar)
Matrix-scalar multiplication assignment.
Definition: matrix.ipp:177
ScalarT min() const
Returns the minimal coefficient.
Definition: matrix.ipp:170
const ScalarT & operator()(std::size_t row, std::size_t col) const
Provides access to a cell.
Definition: matrix.ipp:57
Matrix< ScalarT > & operator-=(const Matrix< ScalarT > &matrix)
Matrix-matrix substraction assignment.
Definition: matrix.ipp:193
std::size_t num_cols() const
Returns the number of columns.
Definition: matrix.ipp:110
Matrix< double > DMatrix
Matrix with double entries.
Definition: matrix.hpp:199
Matrix()
Constructs an empty cost matrix.
Definition: matrix.ipp:39
Matrix< ScalarT > transposed() const
Returns the transposed matrix.
Definition: matrix.ipp:147
Matrix< ScalarT > & operator+=(const Matrix< ScalarT > &matrix)
Matrix-matrix addition assignment.
Definition: matrix.ipp:185
Matrix< int > IMatrix
Matrix with int entries.
Definition: matrix.hpp:204
Eigen::Matrix< ScalarT, Eigen::Dynamic, Eigen::Dynamic > & matrix()
Returns reference to the internal Eigen matrix.
Definition: matrix.ipp:228
Type declarations used by various classes.
Global namespace for GEDLIB.
void operator=(const Matrix &matrix)
Assignment operator.
Definition: matrix.ipp:50
void set_to_val(const ScalarT &val)
Sets all cells to val.
Definition: matrix.ipp:99
void transpose()
Transposes the matrix.
Definition: matrix.ipp:140
ScalarT * data()
Provides access to internal data.
Definition: matrix.ipp:71
std::size_t num_rows() const
Returns the number of rows.
Definition: matrix.ipp:85