|
A library for working with phylogenetic and population genetic data.
v0.32.0
|
|
Go to the documentation of this file. 1 #ifndef GENESIS_UTILS_CONTAINERS_MATRIX_H_
2 #define GENESIS_UTILS_CONTAINERS_MATRIX_H_
72 using iterator =
typename container_type::iterator;
103 throw std::length_error(
104 std::string(__PRETTY_FUNCTION__) +
": length_error. Expecting " +
115 , data_( std::move(
data ))
118 throw std::length_error(
119 std::string(__PRETTY_FUNCTION__) +
": length_error. Expecting " +
132 if (init_list.size() !=
size()) {
133 throw std::length_error(
134 std::string(__PRETTY_FUNCTION__) +
": length_error. Expecting " +
142 for (T
const& v : init_list) {
159 swap(rows_, other.rows_);
160 swap(cols_, other.cols_);
161 swap(data_, other.data_);
170 friend void transpose_inplace<>(
Matrix<T>& );
188 return rows_ * cols_;
207 if (
row >= rows_ ||
col >= cols_) {
208 throw std::out_of_range(
214 return data_[
row * cols_ +
col];
217 T
const&
at (
const size_t row,
const size_t col)
const
219 if (
row >= rows_ ||
col >= cols_) {
220 throw std::out_of_range(
226 return data_[
row * cols_ +
col];
231 assert(
row < rows_ );
232 assert(
col < cols_ );
233 return data_[
row * cols_ +
col];
238 assert(
row < rows_ );
239 assert(
col < cols_ );
240 return data_[
row * cols_ +
col];
250 throw std::out_of_range(
262 throw std::out_of_range(
274 throw std::out_of_range(
286 throw std::out_of_range(
301 return data_.begin();
311 return data_.begin();
321 return data_.cbegin();
335 return rows_ == other.rows_
336 && cols_ == other.cols_
337 && data_ == other.data_;
342 return !(*
this == other);
359 #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)
void transpose_inplace(Matrix< T > &mat)
Transpose a Matrix inplace, without allocating a new Matrix.
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