TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
gtsv.hpp
Go to the documentation of this file.
1// Copyright (c) 2021-2022 Simons Foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0.txt
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Authors: Nils Wentzell
16
17/**
18 * @file
19 * @brief Provides a generic interface to the LAPACK `gtsv` routine.
20 */
21
22#pragma once
23
24#include "./interface/cxx_interface.hpp"
25#include "../concepts.hpp"
26#include "../macros.hpp"
27#include "../mem/address_space.hpp"
28#include "../traits.hpp"
29
30namespace nda::lapack {
31
32 /**
33 * @ingroup linalg_lapack
34 * @brief Interface to the LAPACK `gtsv` routine.
35 *
36 * @details Solves the equation
37 * \f[
38 * \mathbf{A} \mathbf{X} = \mathbf{B},
39 * \f]
40 * where \f$ \mathbf{A} \f$ is an n-by-n tridiagonal matrix, by Gaussian elimination with partial pivoting.
41 *
42 * Note that the equation \f$ \mathbf{A}^T \mathbf{X} = \mathbf{B} \f$ may be solved by interchanging the order of the
43 * arguments containing the subdiagonal elements.
44 *
45 * @tparam DL nda::MemoryVector type.
46 * @tparam D nda::MemoryVector type.
47 * @tparam DU nda::MemoryVector type.
48 * @tparam B nda::MemoryArray type.
49 * @param dl Input/Output vector. On entry, it must contain the (n-1) subdiagonal elements of \f$ \mathbf{A} \f$. On
50 * exit, it is overwritten by the (n-2) elements of the second superdiagonal of the upper triangular matrix
51 * \f$ \mathbf{U} \f$ from the LU factorization of \f$ \mathbf{A} \f$.
52 * @param d Input/Output vector. On entry, it must contain the diagonal elements of \f$ \mathbf{A} \f$. On exit, it is
53 * overwritten by the n diagonal elements of \f$ \mathbf{U} \f$.
54 * @param du Input/Output vector. On entry, it must contain the (n-1) superdiagonal elements of \f$ \mathbf{A} \f$. On
55 * exit, it is overwritten by the (n-1) elements of the first superdiagonal of \f$ \mathbf{U} \f$ .
56 * @param b Input/Output array. On entry, the n-by-nrhs right hand side matrix \f$ \mathbf{B} \f$. On exit, if
57 * `INFO == 0`, the n-by-nrhs solution matrix \f$ \mathbf{X} \f$.
58 * @return Integer return code from the LAPACK call.
59 */
60 template <MemoryVector DL, MemoryVector D, MemoryVector DU, MemoryArray B>
61 requires(have_same_value_type_v<DL, D, DU, B> and mem::on_host<DL, D, DU, B> and is_blas_lapack_v<get_value_t<DL>>)
62 int gtsv(DL &&dl, D &&d, DU &&du, B &&b) { // NOLINT (temporary views are allowed here)
63 static_assert((get_rank<B> == 1 or get_rank<B> == 2), "Error in nda::lapack::gtsv: B must be an matrix/array/view of rank 1 or 2");
64
65 // get and check dimensions of input arrays
66 EXPECTS(dl.extent(0) == d.extent(0) - 1); // "gtsv : dimension mismatch between sub-diagonal and diagonal vectors "
67 EXPECTS(du.extent(0) == d.extent(0) - 1); // "gtsv : dimension mismatch between super-diagonal and diagonal vectors "
68 EXPECTS(b.extent(0) == d.extent(0)); // "gtsv : dimension mismatch between diagonal vector and RHS matrix, "
69
70 // perform actual library call
71 int N = d.extent(0);
72 int NRHS = (get_rank<B> == 2 ? b.extent(1) : 1);
73 int info = 0;
74 f77::gtsv(N, NRHS, dl.data(), d.data(), du.data(), b.data(), N, info);
75 return info;
76 }
77
78} // namespace nda::lapack
int gtsv(DL &&dl, D &&d, DU &&du, B &&b)
Interface to the LAPACK gtsv routine.
Definition gtsv.hpp:62
#define EXPECTS(X)
Definition macros.hpp:59