15 #include <pyre/grid.h>
20 template <
typename cell_t>
25 using rep_t = std::array<size_t, 2>;
26 using index_t = pyre::grid::index_t<rep_t>;
27 using layout_t = pyre::grid::layout_t<index_t>;
30 using grid_t = pyre::grid::grid_t<cell_t, layout_t, pyre::memory::view_t<cell_t>>;
33 using view_t =
typename grid_t::view_type;
34 using shape_t =
typename layout_t::shape_type;
35 using slice_t =
typename layout_t::slice_type;
36 using packing_t =
typename layout_t::packing_type;
43 inline Matrix(
size_t nrows,
size_t ncols);
46 inline Matrix(
const Matrix<cell_t> & m);
49 inline Matrix(Matrix<cell_t> & m);
52 inline Matrix(
const view_t & view);
55 inline Matrix(cell_t *
data,
size_t nrows,
size_t ncols);
58 inline Matrix(std::valarray<cell_t> &
data,
size_t ncols);
61 inline Matrix(std::vector<cell_t> &
data,
size_t ncols);
67 inline Matrix<cell_t> &
operator=(
const Matrix<cell_t> & m);
70 inline Matrix<cell_t> &
operator=(Matrix<cell_t> & m);
73 inline Matrix<cell_t> &
operator=(
const view_t & view);
76 inline void resize(
size_t nrows,
size_t ncols);
79 inline const view_t
submat(
size_t row,
size_t col,
size_t rowspan,
size_t colspan);
82 inline cell_t *
data();
85 inline const cell_t *
data()
const;
88 inline cell_t *
rowptr(
size_t row);
91 inline const cell_t *
rowptr(
size_t row)
const;
94 inline cell_t &
operator()(
size_t row,
size_t col);
97 inline const cell_t &
operator()(
size_t row,
size_t col)
const;
103 inline const cell_t &
operator()(
size_t index)
const;
106 inline cell_t &
operator[](
const index_t & index);
109 inline const cell_t &
operator[](
const index_t & index)
const;
115 inline void fill(cell_t value);
118 inline shape_t
shape()
const;
121 inline size_t width()
const;
124 inline size_t length()
const;
131 return Eigen::Map<const EArray2D<cell_t>> {
132 _buffer,
static_cast<Eigen::Index
>(_nrows),
133 static_cast<Eigen::Index>(_ncols)};
143 cell_t* _buffer =
nullptr;
152 inline void _resetGrid();
156 #define ISCE_CORE_MATRIX_ICC
157 #include "Matrix.icc"
158 #undef ISCE_CORE_MATRIX_ICC
cell_t & operator()(size_t row, size_t col)
Access matrix value for a given row and column.
Definition: Matrix.icc:259
void fill(cell_t value)
Fill with a constant value.
Definition: Matrix.icc:331
const view_t 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.icc:198
void resize(size_t nrows, size_t ncols)
Resize memory for a given number of rows and columns.
Definition: Matrix.icc:173
shape_t byteoffset() const
Get byteoffset for row and column for reading flat binary buffer.
Definition: Matrix.icc:365
Data structure for a 2D row-major matrix.
Definition: forward.h:31
Matrix< cell_t > & operator=(const Matrix< cell_t > &m)
Deep assignment operator - allocates memory and copies values.
Definition: Matrix.icc:123
cell_t * data()
Access to data buffer.
Definition: Matrix.icc:219
size_t length() const
Get matrix length.
Definition: Matrix.icc:357
~Matrix()
Destructor.
Definition: Matrix.icc:107
Matrix()
Default constructor.
Definition: Matrix.icc:14
cell_t & operator[](const index_t &index)
Access matrix value for a given grid::index_type.
Definition: Matrix.icc:296
shape_t shape() const
Get shape information as grid::shape_type.
Definition: Matrix.icc:341
size_t width() const
Get matrix width.
Definition: Matrix.icc:349
cell_t * rowptr(size_t row)
Access to data buffer at a specific row.
Definition: Matrix.icc:235
void zeros()
Fill with zeros.
Definition: Matrix.icc:321