isce3 0.25.0
Loading...
Searching...
No Matches
DenseMatrix.h
1#pragma once
2
3#include "forward.h"
4
5#include <cmath>
6#define EIGEN_MPL2_ONLY
7#include <Eigen/Dense>
8
9#include "Common.h"
10#include "Vector.h"
11
12namespace isce3 { namespace core {
13
14template<int N, typename T>
15class DenseMatrix : public Eigen::Matrix<T, N, N> {
16 using super_t = Eigen::Matrix<T, N, N>;
17 using super_t::super_t;
18
19 static_assert(N > 0);
20
21public:
22 DenseMatrix() = default;
23 CUDA_HOSTDEV auto operator[](int i) { return this->row(i); }
24 CUDA_HOSTDEV auto operator[](int i) const { return this->row(i); }
25
26 CUDA_HOSTDEV auto dot(const DenseMatrix& other) const
27 {
28 return *this * other;
29 }
30
31 CUDA_HOSTDEV auto dot(const Vector<N, T>& other) const
32 {
33 return *this * other;
34 }
35
36// Backport Eigen 3.4.0's initializer_list constructor
37#if !EIGEN_VERSION_AT_LEAST(3, 4, 0)
38 CUDA_HOSTDEV explicit constexpr DenseMatrix(
39 std::initializer_list<std::initializer_list<T>> lst) {
40 int i = 0, j = 0;
41 for (const auto& l : lst) {
42 for (const auto& v : l) {
43 (*this)(i, j++) = v;
44 }
45 i++, j = 0;
46 }
47 }
48#endif
49
51 CUDA_HOSTDEV constexpr DenseMatrix<N, T> transpose() const {
52 DenseMatrix<N, T> out;
53 for (int i = 0; i < N; i++)
54 for (int j = 0; j < N; j++)
55 out[i][j] = (*this)[j][i];
56 return out;
57 }
58
63 CUDA_HOSTDEV static Mat3 xyzToEnu(double lat, double lon);
64
69 CUDA_HOSTDEV static Mat3 enuToXyz(double lat, double lon);
70};
71
72template<int N, typename T>
73CUDA_HOSTDEV Mat3 DenseMatrix<N, T>::xyzToEnu(double lat, double lon) {
74 using std::cos;
75 using std::sin;
76 return Mat3 {{{ -sin(lon), cos(lon), 0.},
77 {-sin(lat)*cos(lon), -sin(lat)*sin(lon), cos(lat)},
78 { cos(lat)*cos(lon), cos(lat)*sin(lon), sin(lat)}}};
79}
80
81template<int N, typename T>
82CUDA_HOSTDEV Mat3 DenseMatrix<N, T>::enuToXyz(double lat, double lon)
83{
84 using std::cos;
85 using std::sin;
86 return Mat3 {{{-sin(lon), -sin(lat) * cos(lon), cos(lat) * cos(lon)},
87 {cos(lon), -sin(lat) * sin(lon), cos(lat) * sin(lon)},
88 {0, cos(lat), sin(lat)}}};
89}
90
91// XXX
92// These overloads are a workaround to resolve an issue observed with certain
93// Eigen & CUDA version combinations where matrix-matrix and matrix-vector
94// multiplication produced incorrect results (or raised "illegal memory access"
95// errors in debug mode).
96template<int N, typename T>
97CUDA_HOSTDEV auto operator*(
98 const DenseMatrix<N, T>& a, const DenseMatrix<N, T>& b)
99{
101 for (int i = 0; i < N; ++i) {
102 for (int j = 0; j < N; ++j) {
103 out(i, j) = a.row(i).dot(b.col(j));
104 }
105 }
106 return out;
107}
108
109template<int N, typename T>
110CUDA_HOSTDEV auto operator*(const DenseMatrix<N, T>& m, const Vector<N, T>& v)
111{
112 Vector<N, T> out;
113 for (int i = 0; i < N; ++i) {
114 out[i] = m.row(i).dot(v);
115 }
116 return out;
117}
118
119}}
Definition DenseMatrix.h:15
CUDA_HOSTDEV constexpr DenseMatrix< N, T > transpose() const
Matrix transposition.
Definition DenseMatrix.h:51
static CUDA_HOSTDEV Mat3 enuToXyz(double lat, double lon)
Compute ENU basis inverse transformation matrix.
Definition DenseMatrix.h:82
static CUDA_HOSTDEV Mat3 xyzToEnu(double lat, double lon)
Compute ENU basis transformation matrix.
Definition DenseMatrix.h:73
Definition Vector.h:14
base interpolator is an abstract base class
Definition BinarySearchFunc.cpp:5

Generated for ISCE3.0 by doxygen 1.13.2.