TRIQS/nda
2.0.0
Multi-dimensional array library for C++
Toggle main menu visibility
Loading...
Searching...
No Matches
getri.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
13
#include "
./interface/cxx_interface.hpp
"
14
#include "
../basic_array.hpp
"
15
#include "
../concepts.hpp
"
16
#include "
../declarations.hpp
"
17
#include "
../macros.hpp
"
18
#include "
../mem/address_space.hpp
"
19
#include "
../traits.hpp
"
20
21
#include <cmath>
22
#include <complex>
23
#include <type_traits>
24
25
namespace
nda::lapack {
26
46
template
<MemoryMatrix A, MemoryVector IPIV>
47
requires
(
mem::have_host_compatible_addr_space<A, IPIV>
and
is_blas_lapack_v<get_value_t<A>
> and std::is_same_v<get_value_t<IPIV>,
int
>)
48
int
getri
(A &&a, IPIV
const
&ipiv) {
// NOLINT (temporary views are allowed here)
49
// check the dimensions of the input/output arrays/views
50
auto
const
[m, n] = a.shape();
51
EXPECTS(m == n);
52
EXPECTS(ipiv.size() == n);
53
54
// arrays/views must be LAPACK compatible
55
EXPECTS(a.indexmap().min_stride() == 1);
56
EXPECTS(ipiv.indexmap().min_stride() == 1);
57
58
// first call to get the optimal buffer size
59
using
value_type =
get_value_t<A>
;
60
int
info = 0;
61
value_type tmp_lwork{};
62
f77::getri(n, a.data(),
get_ld
(a), ipiv.data(), &tmp_lwork, -1, info);
63
int
lwork =
static_cast<
int
>
(std::ceil(std::real(tmp_lwork)));
64
65
// allocate work buffer and perform actual library call
66
array<value_type, 1>
work(lwork);
67
#if defined(__has_feature)
68
#if __has_feature(memory_sanitizer)
69
work = 0;
70
#endif
71
#endif
72
f77::getri(n, a.data(),
get_ld
(a), ipiv.data(), work.
data
(), lwork, info);
73
74
return
info;
75
}
76
77
}
// namespace nda::lapack
address_space.hpp
Provides definitions and type traits involving the different memory address spaces supported by nda.
basic_array.hpp
Provides the generic class for arrays.
nda::basic_array::data
ValueType const * data() const noexcept
Get a pointer to the actual data (in general this is not the beginning of the memory block for a view...
Definition
basic_array.hpp:619
concepts.hpp
Provides concepts for the nda library.
declarations.hpp
Provides various convenient aliases and helper functions for nda::basic_array and nda::basic_array_vi...
nda::array
basic_array< ValueType, Rank, Layout, 'A', ContainerPolicy > array
Alias template of an nda::basic_array with an 'A' algebra.
Definition
declarations.hpp:64
nda::get_value_t
std::decay_t< decltype(get_first_element(std::declval< A const >()))> get_value_t
Get the value type of an array/view or a scalar type.
Definition
traits.hpp:191
nda::lapack::getri
int getri(A &&a, IPIV const &ipiv)
Interface to the LAPACK getri routine.
Definition
getri.hpp:48
nda::mem::have_host_compatible_addr_space
static constexpr bool have_host_compatible_addr_space
Constexpr variable that is true if all given types have an address space compatible with Host.
Definition
address_space.hpp:173
nda::is_blas_lapack_v
constexpr bool is_blas_lapack_v
Alias for nda::is_double_or_complex_v.
Definition
traits.hpp:92
cxx_interface.hpp
Provides a C++ interface for various LAPACK routines.
nda::lapack::get_ld
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
macros.hpp
Macros used in the nda library.
traits.hpp
Provides type traits for the nda library.
nda
lapack
getri.hpp
Generated by
1.17.0