DP3
QRSolver.h
Go to the documentation of this file.
1 // Copyright (C) 2020 ASTRON (Netherlands Institute for Radio Astronomy)
2 // SPDX-License-Identifier: GPL-3.0-or-later
3 
4 #ifndef QR_SOLVER_H
5 #define QR_SOLVER_H
6 
7 #include <complex>
8 #include <vector>
9 #include <cmath>
10 
11 #include "LLSSolver.h"
12 
13 namespace dp3 {
14 namespace ddecal {
15 
16 using complex = std::complex<float>;
17 
18 /* CGELS prototype */
19 extern "C" void cgels_(char* trans, int* m, int* n, int* nrhs, complex* a,
20  int* lda, complex* b, int* ldb, complex* work,
21  int* lwork, int* info);
22 
23 class QRSolver final : public LLSSolver {
24  public:
25  QRSolver(int m, int n, int nrhs) : LLSSolver(m, n, nrhs) {}
26 
35  bool Solve(complex* a, complex* b) override {
36  if (m_ < n_) return false;
37  int info;
38  char trans = 'N'; // No transpose
39  int ldb = std::max(m_, n_);
40  if (_work.empty()) {
41  int lwork = -1;
42  complex wkopt;
43  cgels_(&trans, &m_, &n_, &nrhs_, a, &m_, b, &ldb, &wkopt, &lwork, &info);
44  _work.resize((int)wkopt.real());
45  }
46  int lwork = _work.size();
47  cgels_(&trans, &m_, &n_, &nrhs_, a, &m_, b, &ldb, _work.data(), &lwork,
48  &info);
50  return info == 0;
51  }
52 
53  private:
54  std::vector<complex> _work;
55 };
56 
57 } // namespace ddecal
58 } // namespace dp3
59 
60 #endif
Definition: LLSSolver.h:25
int m_
Definition: LLSSolver.h:44
int n_
Definition: LLSSolver.h:45
int nrhs_
Definition: LLSSolver.h:46
std::complex< float > complex
Definition: LLSSolver.h:27
Definition: QRSolver.h:23
bool Solve(complex *a, complex *b) override
Definition: QRSolver.h:35
QRSolver(int m, int n, int nrhs)
Definition: QRSolver.h:25
std::complex< float > complex
Definition: QRSolver.h:16
void cgels_(char *trans, int *m, int *n, int *nrhs, complex *a, int *lda, complex *b, int *ldb, complex *work, int *lwork, int *info)
This file has generic helper routines for testing steps.
Definition: AntennaConfig.h:53