isce3 0.25.0
Loading...
Searching...
No Matches
Presum.icc
1
2#include <isce3/core/TypeTraits.h>
3#include <isce3/except/Error.h>
4#include <Eigen/Dense>
5
6namespace isce3 { namespace focus {
7
8template<typename KernelType>
9auto
10getPresumWeights(const KernelType& acorr,
11 const Eigen::Ref<const Eigen::VectorXd>& xin, double xout,
12 long* offset)
13{
14 // Sanity check: autocorrelation function is real-valued by definition.
15 using KT = typename KernelType::value_type;
16 static_assert(not isce3::is_complex<KT>());
17
18 // Make sure we can store offset.
19 if (offset == nullptr) {
20 throw isce3::except::InvalidArgument(
21 ISCE_SRCINFO(), "no storage provided for index offset");
22 }
23
24 // Find time samples where autocorrelation function is nonzero.
25 const double hw = 0.5 * acorr.width();
26 const auto xend = xin.data() + xin.size();
27 auto first = std::lower_bound(xin.data(), xend, xout - hw);
28 auto last = std::upper_bound(first, xend, xout + hw);
29
30 // Convert iterator to index.
31 const long offset_ = std::distance(xin.data(), first);
32
33 // Allocate temporary storage.
34 auto n = std::distance(first, last);
35 using Mat = Eigen::Matrix<KT, Eigen::Dynamic, Eigen::Dynamic>;
36 using Vec = Eigen::Matrix<KT, Eigen::Dynamic, 1>;
37 Mat g(n, n);
38 Vec r(n);
39
40 // Compute the autocorrelation matrix and right-hand-side vector.
41 for (int i = 0; i < n; ++i) {
42 const auto xi = xin[offset_ + i];
43 for (int j = i; j < n; ++j) { // NOTE j=i for lower half
44 const auto xj = xin[offset_ + j];
45 // Hermitian matrix, and LDLT only requires that we fill lower half.
46 g(j, i) = acorr(xj - xi);
47 }
48 r(i) = acorr(xout - xi);
49 }
50
51 // Solve with Cholesky decomposition since covariance matrix is always
52 // positive semi-definite (called LDLT in Eigen).
53 Vec w = g.ldlt().solve(r);
54
55 *offset = offset_;
56 return w;
57}
58
59
60// STL overload
61template<typename KernelType>
62auto
63getPresumWeights(const KernelType& acorr,
64 const std::vector<double>& xin, double xout,
65 long* offset)
66{
67 Eigen::Map<const Eigen::VectorXd> xmap(xin.data(), xin.size());
68 return getPresumWeights(acorr, xmap, xout, offset);
69}
70
71}}
base interpolator is an abstract base class
Definition BinarySearchFunc.cpp:5

Generated for ISCE3.0 by doxygen 1.13.2.