TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
getrf.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
15#include "../concepts.hpp"
17#include "../macros.hpp"
19#include "../traits.hpp"
20
21#ifndef NDA_HAVE_DEVICE
22#include "../device.hpp"
23#endif // NDA_HAVE_DEVICE
24
25#include <algorithm>
26#include <type_traits>
27
28namespace nda::lapack {
29
56 template <MemoryMatrix A, MemoryVector IPIV>
57 requires(mem::have_compatible_addr_space<A, IPIV> and is_blas_lapack_v<get_value_t<A>> and std::is_same_v<get_value_t<IPIV>, int>)
58 int getrf(A &&a, IPIV &&ipiv) { // NOLINT (temporary views are allowed here)
59 // for C-layout arrays/views, call getrf with the transpose
60 if constexpr (has_C_layout<A>) return getrf(transpose(a), ipiv);
61
62 // check the dimensions of the input/output arrays/views and resize if necessary
63 auto const [m, n] = a.shape();
64 resize_or_check_if_view(ipiv, {std::min(m, n)});
65
66 // arrays/views must be LAPACK compatible
67 EXPECTS(a.indexmap().min_stride() == 1);
68 EXPECTS(ipiv.indexmap().min_stride() == 1);
69
70#if defined(__has_feature)
71#if __has_feature(memory_sanitizer)
72 ipiv = 0;
73#endif
74#endif
75
76 // perform actual library call
77 int info = 0;
79#if defined(NDA_HAVE_DEVICE)
80 device::getrf(m, n, a.data(), get_ld(a), ipiv.data(), info);
81#else
83#endif
84 } else {
85 f77::getrf(m, n, a.data(), get_ld(a), ipiv.data(), info);
86 }
87 return info;
88 }
89
90} // namespace nda::lapack
Provides definitions and type traits involving the different memory address spaces supported by nda.
Provides basic functions to create and manipulate arrays and views.
Provides concepts for the nda library.
Provides GPU and non-GPU specific functionality.
void resize_or_check_if_view(A &a, std::array< long, A::rank > const &sha)
Resize a given regular array to the given shape or check if a given view as the correct shape.
auto transpose(A &&a)
Transpose the memory layout of an nda::MemoryArray or an nda::expr_call.
int getrf(A &&a, IPIV &&ipiv)
Interface to the LAPACK getrf routine.
Definition getrf.hpp:58
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.
static constexpr bool has_C_layout
Constexpr variable that is true if the given nda::Array type has nda::C_layout.
Definition tools.hpp:83
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
Provides functions to transform the memory layout of an nda::basic_array or nda::basic_array_view.
Macros used in the nda library.
Provides type traits for the nda library.