Tatooine
geqrf.h
Go to the documentation of this file.
1#ifndef TATOOINE_LAPACK_GEQRF_H
2#define TATOOINE_LAPACK_GEQRF_H
3//==============================================================================
4extern "C" {
5auto dgeqrf_(int* M, int* N, double* A, int* LDA, double* TAU, double* WORK,
6 int* LWORK, int* INFO) -> void;
7auto sgeqrf_(int* M, int* N, float* A, int* LDA, float* TAU, float* WORK,
8 int* LWORK, int* INFO) -> void;
9}
10//==============================================================================
12#include <concepts>
13#include <memory>
14//==============================================================================
15namespace tatooine::lapack {
16//==============================================================================
17template <std::floating_point Float>
18auto geqrf(int M, int N, Float* A, int LDA, Float* TAU, Float* WORK, int LWORK)
19 -> int {
20 auto INFO = int{};
21 if constexpr (std::same_as<Float, double>) {
22 dgeqrf_(&M, &N, A, &LDA, TAU, WORK, &LWORK, &INFO);
23 } else if constexpr (std::same_as<Float, float>) {
24 sgeqrf_(&M, &N, A, &LDA, TAU, WORK, &LWORK, &INFO);
25 }
26 return INFO;
27}
28//==============================================================================
29template <std::floating_point Float>
30auto geqrf(int M, int N, Float* A, int LDA, Float* TAU) -> int {
31 auto LWORK = int{-1};
32 auto WORK = std::unique_ptr<Float[]>{new Float[1]};
33
34 geqrf<Float>(M, N, A, LDA, TAU, WORK.get(), LWORK);
35 LWORK = static_cast<int>(WORK[0]);
36 WORK = std::unique_ptr<Float[]>{new Float[LWORK]};
37 return geqrf<Float>(M, N, A, LDA, TAU, WORK.get(), LWORK);
38}
39//==============================================================================
48//==============================================================================
49template <typename T, size_t M, size_t N>
50auto geqrf(tensor<T, M, N>& A, tensor<T, (M < N) ? M : N>& tau) {
51 return geqrf(M, N, A.data(), M, tau.data());
52}
53// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
54template <typename T>
55auto geqrf(tensor<T>& A, tensor<T>& tau) {
56 assert(A.rank() == 2);
57 auto const M = A.dimension(0);
58 auto const N = A.dimension(1);
59 assert(tau.rank() == 1);
60 assert(tau.dimension(0) >= tatooine::min(M, N));
61 return geqrf(static_cast<int>(M), static_cast<int>(N), A.data(),
62 static_cast<int>(M), tau.data());
63}
64//==============================================================================
66//==============================================================================
67} // namespace tatooine::lapack
68//==============================================================================
69#endif
constexpr auto data() -> ValueType *
Definition: static_multidim_array.h:260
auto sgeqrf_(int *M, int *N, float *A, int *LDA, float *TAU, float *WORK, int *LWORK, int *INFO) -> void
auto dgeqrf_(int *M, int *N, double *A, int *LDA, double *TAU, double *WORK, int *LWORK, int *INFO) -> void
Definition: base.h:6
auto geqrf(int M, int N, Float *A, int LDA, Float *TAU, Float *WORK, int LWORK) -> int
Definition: geqrf.h:18
constexpr auto min(A &&a, B &&b)
Definition: math.h:15
Definition: tensor.h:17
static auto constexpr rank()
Definition: base_tensor.h:41
static auto constexpr dimension(std::size_t const i)
Definition: base_tensor.h:49