22 public Eigen::Array<T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>
25 using super_t = Eigen::Array<T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
28 using index_t =
typename super_t::Index;
34 Matrix(index_t rows, index_t cols) : super_t(rows, cols) {}
36 template<
typename Derived>
37 Matrix(
const Eigen::Block<Derived>& b) : super_t(b) {}
40 Matrix(T * data,
size_t nrows,
size_t ncols) :
41 super_t(Eigen::Map<super_t>(data, nrows, ncols))
43 assert(ncols <= std::numeric_limits<Eigen::Index>::max());
44 assert(nrows <= std::numeric_limits<Eigen::Index>::max());
48 Matrix(std::valarray<T> & data,
size_t ncols) :
49 super_t(Eigen::Map<super_t>(data.data(), data.size() / ncols, ncols))
51 assert(ncols <= std::numeric_limits<Eigen::Index>::max());
55 Matrix(std::vector<T> & data,
size_t ncols) :
56 super_t(Eigen::Map<super_t>(data.data(), data.size() / ncols, ncols))
58 assert(ncols <= std::numeric_limits<Eigen::Index>::max());
62 auto submat(
size_t row,
size_t col,
size_t rowspan,
size_t colspan) {
63 assert(col <= std::numeric_limits<Eigen::Index>::max());
64 assert(row <= std::numeric_limits<Eigen::Index>::max());
65 assert(colspan <= std::numeric_limits<Eigen::Index>::max());
66 assert(rowspan <= std::numeric_limits<Eigen::Index>::max());
67 return this->block(row, col, rowspan, colspan);
74 size_t width()
const {
return this->cols(); }
77 size_t length()
const {
return this->rows(); }
80 return Eigen::Map<const super_t> {
Data structure for a 2D row-major matrix.
Definition Matrix.h:23
size_t length() const
Get matrix length.
Definition Matrix.h:77
void zeros()
Fill with zeros.
Definition Matrix.h:71
Matrix(T *data, size_t nrows, size_t ncols)
Copy constructor from raw pointer to data.
Definition Matrix.h:40
Matrix()
Default constructor.
Definition Matrix.h:32
Matrix(std::vector< T > &data, size_t ncols)
Copy constructor from an std::vector.
Definition Matrix.h:55
Matrix(std::valarray< T > &data, size_t ncols)
Copy constructor from an std::valarray.
Definition Matrix.h:48
size_t width() const
Get matrix width.
Definition Matrix.h:74
auto submat(size_t row, size_t col, size_t rowspan, size_t colspan)
Extract copy of sub-matrix given starting indices and span.
Definition Matrix.h:62