|
A library for working with phylogenetic and population genetic data.
v0.27.0
|
|
Go to the documentation of this file. 1 #ifndef GENESIS_UTILS_CONTAINERS_MATRIX_H_
2 #define GENESIS_UTILS_CONTAINERS_MATRIX_H_
61 using iterator =
typename container_type::iterator;
92 throw std::length_error(
93 std::string(__PRETTY_FUNCTION__) +
": length_error. Expecting " +
104 , data_( std::move(
data ))
107 throw std::length_error(
108 std::string(__PRETTY_FUNCTION__) +
": length_error. Expecting " +
121 if (init_list.size() !=
size()) {
122 throw std::length_error(
123 std::string(__PRETTY_FUNCTION__) +
": length_error. Expecting " +
131 for (T
const& v : init_list) {
148 swap(rows_, other.rows_);
149 swap(cols_, other.cols_);
150 swap(data_, other.data_);
174 return rows_ * cols_;
193 if (
row >= rows_ ||
col >= cols_) {
194 throw std::out_of_range(
"Matrix index out of range." );
196 return data_[
row * cols_ +
col];
199 T
const&
at (
const size_t row,
const size_t col)
const
201 if (
row >= rows_ ||
col >= cols_) {
202 throw std::out_of_range(
"Matrix index out of range." );
204 return data_[
row * cols_ +
col];
209 return data_[
row * cols_ +
col];
214 return data_[
row * cols_ +
col];
224 throw std::out_of_range(
"Matrix row index out of range." );
233 throw std::out_of_range(
"Matrix row index out of range." );
242 throw std::out_of_range(
"Matrix column index out of range." );
251 throw std::out_of_range(
"Matrix column index out of range." );
263 return data_.begin();
273 return data_.begin();
283 return data_.cbegin();
297 return rows_ == other.rows_
298 && cols_ == other.cols_
299 && data_ == other.data_;
304 return !(*
this == other);
321 #endif // include guard
void swap(Sample &lhs, Sample &rhs)
friend void swap(Matrix &lhs, Matrix &rhs)
const_iterator end() const
bool operator!=(Matrix< T > const &other) const
Matrix(size_t rows, size_t cols, std::initializer_list< T > const &init_list)
MatrixCol< self_type, value_type > col(size_t col)
Matrix(size_t rows, size_t cols, std::vector< T > &&data)
T const & at(const size_t row, const size_t col) const
std::string to_string(GenomeLocus const &locus)
T & operator()(const size_t row, const size_t col)
const_iterator cend() const
Matrix(size_t rows, size_t cols, std::vector< T > const &data)
bool operator==(Matrix< T > const &other) const
T & at(const size_t row, const size_t col)
typename container_type::const_iterator const_iterator
container_type const & data() const
View into a Matrix column.
Matrix & operator=(Matrix const &)=default
MatrixCol< const self_type, const value_type > col(size_t col) const
Matrix(size_t rows, size_t cols)
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
typename container_type::iterator iterator
Matrix(size_t rows, size_t cols, T init)
const_iterator cbegin() const
std::vector< size_t > container_type
MatrixRow< self_type, value_type > row(size_t row)
MatrixRow< const self_type, const value_type > row(size_t row) const
const_iterator begin() const