isce3  0.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
Matrix.h
1 //-*- C++ -*-
2 //-*- coding: utf-8 -*-
3 //
4 // Author: Bryan V. Riel
5 // Copyright 2017-2018
6 
7 #pragma once
8 
9 #include "forward.h"
10 
11 #include <cmath>
12 #include <valarray>
13 #include <vector>
14 
15 #include <pyre/grid.h>
16 
17 #include "EMatrix.h"
18 
20 template <typename cell_t>
21 class isce3::core::Matrix {
22 
23  public:
24  // Types for interfacing with pyre::grid
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>;
28 
29  // Use a grid with view memory storage
30  using grid_t = pyre::grid::grid_t<cell_t, layout_t, pyre::memory::view_t<cell_t>>;
31 
32  // Dependent types
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;
37 
38  public:
40  inline Matrix();
41 
43  inline Matrix(size_t nrows, size_t ncols);
44 
46  inline Matrix(const Matrix<cell_t> & m);
47 
49  inline Matrix(Matrix<cell_t> & m);
50 
52  inline Matrix(const view_t & view);
53 
55  inline Matrix(cell_t * data, size_t nrows, size_t ncols);
56 
58  inline Matrix(std::valarray<cell_t> & data, size_t ncols);
59 
61  inline Matrix(std::vector<cell_t> & data, size_t ncols);
62 
64  inline ~Matrix();
65 
67  inline Matrix<cell_t> & operator=(const Matrix<cell_t> & m);
68 
70  inline Matrix<cell_t> & operator=(Matrix<cell_t> & m);
71 
73  inline Matrix<cell_t> & operator=(const view_t & view);
74 
76  inline void resize(size_t nrows, size_t ncols);
77 
79  inline const view_t submat(size_t row, size_t col, size_t rowspan, size_t colspan);
80 
82  inline cell_t * data();
83 
85  inline const cell_t * data() const;
86 
88  inline cell_t * rowptr(size_t row);
89 
91  inline const cell_t * rowptr(size_t row) const;
92 
94  inline cell_t & operator()(size_t row, size_t col);
95 
97  inline const cell_t & operator()(size_t row, size_t col) const;
98 
100  inline cell_t & operator()(size_t index);
101 
103  inline const cell_t & operator()(size_t index) const;
104 
106  inline cell_t & operator[](const index_t & index);
107 
109  inline const cell_t & operator[](const index_t & index) const;
110 
112  inline void zeros();
113 
115  inline void fill(cell_t value);
116 
118  inline shape_t shape() const;
119 
121  inline size_t width() const;
122 
124  inline size_t length() const;
125 
127  inline shape_t byteoffset() const;
128 
129  auto map() const
130  {
131  return Eigen::Map<const EArray2D<cell_t>> {
132  _buffer, static_cast<Eigen::Index>(_nrows),
133  static_cast<Eigen::Index>(_ncols)};
134  }
135 
136  // Data members
137  private:
138  // Shape information
139  size_t _nrows;
140  size_t _ncols;
141 
142  // Dynamic memory data
143  cell_t* _buffer = nullptr;
144  bool _owner;
145 
146  // grid pointer for slicing support
147  grid_t * _grid;
148 
149  // Utility functions
150  private:
151  // Reset grid pointer
152  inline void _resetGrid();
153 };
154 
155 // Get inline implementations for Matrix
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

Generated for ISCE3.0 by doxygen 1.8.5.