isce3 0.25.0
Loading...
Searching...
No Matches
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 <cassert>
12#include <cmath>
13#include <limits>
14#include <valarray>
15#include <vector>
16
17#include "EMatrix.h"
18
20template <typename T>
22 public Eigen::Array<T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>
23{
24
25 using super_t = Eigen::Array<T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
26
27 public:
28 using index_t = typename super_t::Index;
29
30 public:
32 Matrix() : super_t(0, 0) {}
33
34 Matrix(index_t rows, index_t cols) : super_t(rows, cols) {}
35
36 template<typename Derived>
37 Matrix(const Eigen::Block<Derived>& b) : super_t(b) {}
38
40 Matrix(T * data, size_t nrows, size_t ncols) :
41 super_t(Eigen::Map<super_t>(data, nrows, ncols))
42 {
43 assert(ncols <= std::numeric_limits<Eigen::Index>::max());
44 assert(nrows <= std::numeric_limits<Eigen::Index>::max());
45 }
46
48 Matrix(std::valarray<T> & data, size_t ncols) :
49 super_t(Eigen::Map<super_t>(data.data(), data.size() / ncols, ncols))
50 {
51 assert(ncols <= std::numeric_limits<Eigen::Index>::max());
52 }
53
55 Matrix(std::vector<T> & data, size_t ncols) :
56 super_t(Eigen::Map<super_t>(data.data(), data.size() / ncols, ncols))
57 {
58 assert(ncols <= std::numeric_limits<Eigen::Index>::max());
59 }
60
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);
68 }
69
71 void zeros() { this->fill(0); }
72
74 size_t width() const { return this->cols(); }
75
77 size_t length() const { return this->rows(); }
78
79 auto map() const {
80 return Eigen::Map<const super_t> {
81 this->data(),
82 this->rows(),
83 this->cols(),
84 };
85 }
86
87};
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

Generated for ISCE3.0 by doxygen 1.13.2.