TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
getrs.hpp
Go to the documentation of this file.
1// Copyright (c) 2021--present, The Simons Foundation
2// This file is part of TRIQS/nda and is licensed under the Apache License, Version 2.0.
3// SPDX-License-Identifier: Apache-2.0
4// See LICENSE in the root of this distribution for details.
5
10
11#pragma once
12
14#include "../concepts.hpp"
15#include "../declarations.hpp"
16#include "../macros.hpp"
18#include "../traits.hpp"
19
20#ifndef NDA_HAVE_DEVICE
21#include "../device.hpp"
22#endif // NDA_HAVE_DEVICE
23
24#include <type_traits>
25
26namespace nda::lapack {
27
50 template <Matrix A, MemoryArray B, MemoryVector IPIV>
51 requires((MemoryMatrix<A> or is_conj_array_expr<A>)
53 int getrs(A const &a, B &&b, IPIV const &ipiv) { // NOLINT (temporary views are allowed here)
54 static_assert(std::is_same_v<get_value_t<IPIV>, int>, "Error in nda::lapack::getrs: Pivoting array must have elements of type int");
55 static_assert(get_rank<B> == 1 || get_rank<B> == 2, "Error in nda::lapack::getrs: Right hand side must have rank 1 or 2");
56 static_assert(has_F_layout<B>, "Error in nda::lapack::getrs: B must have Fortran layout");
57
58 // get underlying matrix in case it is given as a lazy conjugate expression
59 auto &a_mat = get_array(a);
60
61 // check the dimensions of the input/output arrays/views
62 EXPECTS(a_mat.shape()[0] == a_mat.shape()[1]);
63 EXPECTS(b.extent(0) == a_mat.shape()[0]);
64 EXPECTS(ipiv.size() == a_mat.shape()[0]);
65
66 // arrays/views must be LAPACK compatible
67 EXPECTS(a_mat.indexmap().min_stride() == 1);
68 EXPECTS(b.indexmap().min_stride() == 1);
69 EXPECTS(ipiv.indexmap().min_stride() == 1);
70
71 // perform actual library call
72 int info = 0;
74#if defined(NDA_HAVE_DEVICE)
75 device::getrs(get_op<A>, get_ncols(a_mat), get_ncols(b), a_mat.data(), get_ld(a_mat), ipiv.data(), b.data(), get_ld(b), info);
76#else
78#endif
79 } else {
80 f77::getrs(get_op<A>, get_ncols(a_mat), get_ncols(b), a_mat.data(), get_ld(a_mat), ipiv.data(), b.data(), get_ld(b), info);
81 }
82
83 return info;
84 }
85
86} // namespace nda::lapack
Provides definitions and type traits involving the different memory address spaces supported by nda.
Provides concepts for the nda library.
Provides various convenient aliases and helper functions for nda::basic_array and nda::basic_array_vi...
Provides GPU and non-GPU specific functionality.
constexpr bool have_same_value_type_v
Constexpr variable that is true if all types in As have the same value type as A0.
Definition traits.hpp:186
constexpr int get_rank
Constexpr variable that specifies the rank of an nda::Array or of a contiguous 1-dimensional range.
Definition traits.hpp:126
int getrs(A const &a, B &&b, IPIV const &ipiv)
Interface to the LAPACK getrs routine.
Definition getrs.hpp:53
static constexpr bool have_compatible_addr_space
Constexpr variable that is true if all given types have compatible address spaces.
static constexpr bool have_device_compatible_addr_space
Constexpr variable that is true if all given types have an address space compatible with Device.
void compile_error_no_gpu()
Trigger a compilation error in case GPU specific functionality is used without configuring the projec...
Definition device.hpp:36
constexpr bool is_blas_lapack_v
Alias for nda::is_double_or_complex_v.
Definition traits.hpp:92
Provides a C++ interface for various LAPACK routines.
int get_ncols(A const &a)
Get the number of columns of an nda::MemoryArray with rank 1 or 2 for BLAS/LAPACK calls.
Definition tools.hpp:142
int get_ld(A const &a)
Get the leading dimension of an nda::MemoryArray with rank 1 or 2 for BLAS/LAPACK calls.
Definition tools.hpp:122
static constexpr bool is_conj_array_expr
Constexpr variable that is true if the given type is a conjugate lazy expression.
Definition tools.hpp:41
static constexpr char get_op
Variable template that determines the BLAS matrix operation tag ('N','T','C') based on the given bool...
Definition tools.hpp:98
static constexpr bool has_F_layout
Constexpr variable that is true if the given nda::Array type has nda::F_layout.
Definition tools.hpp:73
MemoryArray decltype(auto) get_array(A &&a)
Get the underlying array of a conjugate lazy expression or return the array itself in case it is an n...
Definition tools.hpp:62
Macros used in the nda library.
Provides type traits for the nda library.