Tatooine
sysv.h
Go to the documentation of this file.
1#ifndef TATOOINE_LAPACK_SYSV_H
2#define TATOOINE_LAPACK_SYSV_H
3//==============================================================================
4extern "C" {
5//==============================================================================
6auto dsysv_(char* UPLO, int* N, int* NRHS, double* A, int* LDA, int* IPIV,
7 double* B, int* LDB, double* WORK, int* LWORK, int* INFO) -> void;
8//------------------------------------------------------------------------------
9auto ssysv_(char* UPLO, int* N, int* NRHS, float* A, int* LDA, int* IPIV,
10 float* B, int* LDB, float* WORK, int* LWORK, int* INFO) -> void;
11//==============================================================================
12} // extern "C"
13//==============================================================================
15//==============================================================================
16namespace tatooine::lapack {
17//==============================================================================
37//==============================================================================
38template <std::floating_point Float>
39auto sysv(uplo u, int N, int NRHS, Float* A, int LDA, int* IPIV, Float* B,
40 int LDB, Float* WORK, int LWORK) -> int {
41 auto INFO = int{};
42 if constexpr (std::same_as<Float, double>) {
43 dsysv_(reinterpret_cast<char*>(&u), &N, &NRHS, A, &LDA, IPIV, B, &LDB, WORK, &LWORK, &INFO);
44 } else if constexpr (std::same_as<Float, float>) {
45 ssysv_(reinterpret_cast<char*>(&u), &N, &NRHS, A, &LDA, IPIV, B, &LDB, WORK,
46 &LWORK, &INFO);
47 }
48 return INFO;
49}
50//------------------------------------------------------------------------------
51template <std::floating_point Float>
52auto sysv(uplo u, int N, int NRHS, Float* A, int LDA, int* IPIV, Float* B,
53 int LDB) -> int {
54 auto LWORK = int{-1};
55 auto WORK = std::unique_ptr<Float[]>{new Float[1]};
56 sysv<Float>(u, N, NRHS, A, LDA, IPIV, B, LDB, WORK.get(), LWORK);
57 LWORK = static_cast<int>(WORK[0]);
58 WORK = std::unique_ptr<Float[]>{new Float[LWORK]};
59 return sysv<Float>(u, N, NRHS, A, LDA, IPIV, B, LDB, WORK.get(), LWORK);
60}
61//------------------------------------------------------------------------------
62template <std::floating_point Float, size_t N>
63auto sysv(tensor<Float, N, N>& A, tensor<Float, N>& b, uplo const u) {
64 auto ipiv = std::unique_ptr<std::int64_t[]>(new std::int64_t[N]);
65 return sysv<Float>(u, N, 1, A.data(), N, ipiv.get(), b.data(),
66 N);
67}
68// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
69template <std::floating_point Float>
70auto sysv(tensor<Float>& A, tensor<Float>& B, uplo const u) {
71 assert(A.rank() == 2);
72 assert(B.rank() == 1 || B.rank() == 2);
73 assert(A.dimension(0) == A.dimension(1));
74 assert(A.dimension(0) == B.dimension(0));
75 auto const N = A.dimension(0);
76 auto ipiv = std::unique_ptr<int[]>(new int[N]);
77
78 return sysv<Float>(u, static_cast<int>(N),
79 B.rank() == 1 ? 1 : static_cast<int>(B.dimension(1)),
80 A.data(), static_cast<int>(N), ipiv.get(), B.data(),
81 static_cast<int>(N));
82}
83// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
92//template <typename T>
93//auto sysv_aa(tensor<T>& A, tensor<T>& B, uplo const u) {
94// assert(A.rank() == 2);
95// assert(B.rank() == 1 || B.rank() == 2);
96// assert(A.dimension(0) == A.dimension(1));
97// assert(A.dimension(0) == B.dimension(0));
98// auto const N = A.dimension(0);
99// auto ipiv = std::unique_ptr<std::int64_t[]>(new std::int64_t[N]);
100//
101// return sysv_aa(u, N, B.dimension(1), A.data(), N, ipiv.get(),
102// B.data(), N);
103//}
104// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
122//template <typename T>
123//auto sysv_rk(tensor<T>& A, tensor<T>& B, uplo const u) {
124// assert(A.rank() == 2);
125// assert(B.rank() == 1 || B.rank() == 2);
126// assert(A.dimension(0) == A.dimension(1));
127// assert(A.dimension(0) == B.dimension(0));
128// auto const N = A.dimension(0);
129// auto ipiv = std::unique_ptr<std::int64_t[]>(new std::int64_t[N]);
130//
131// return sysv_rk(u, N, B.rank() == 1 ? 1 : B.dimension(1),
132// A.data(), N, ipiv.get(), B.data(), N);
133//}
134//==============================================================================
136//==============================================================================
137} // namespace tatooine::lapack
138//==============================================================================
139#endif
constexpr auto data() -> ValueType *
Definition: static_multidim_array.h:260
auto sysv(uplo u, int N, int NRHS, Float *A, int LDA, int *IPIV, Float *B, int LDB, Float *WORK, int LWORK) -> int
Definition: sysv.h:39
Definition: base.h:6
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
auto dsysv_(char *UPLO, int *N, int *NRHS, double *A, int *LDA, int *IPIV, double *B, int *LDB, double *WORK, int *LWORK, int *INFO) -> void
auto ssysv_(char *UPLO, int *N, int *NRHS, float *A, int *LDA, int *IPIV, float *B, int *LDB, float *WORK, int *LWORK, int *INFO) -> void