TRIQS/nda 1.3.0
Multi-dimensional array library for C++
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
14#include "../concepts.hpp"
15#include "../declarations.hpp"
16#include "../exceptions.hpp"
17#include "../macros.hpp"
19#include "../traits.hpp"
20
21#include <algorithm>
22#include <cmath>
23#include <complex>
24#include <type_traits>
25
26namespace nda::lapack {
27
46 template <MemoryMatrix A, MemoryVector IPIV>
48 int getri(A &&a, IPIV const &ipiv) { // NOLINT (temporary views are allowed here)
49 static_assert(std::is_same_v<get_value_t<IPIV>, int>, "Error in nda::lapack::getri: Pivoting array must have elements of type int");
50 auto dm = std::min(a.extent(0), a.extent(1));
51
52 if (ipiv.size() < dm)
53 NDA_RUNTIME_ERROR << "Error in nda::lapack::getri: Pivot index array size " << ipiv.size() << " smaller than required size " << dm;
54
55 // must be lapack compatible
56 EXPECTS(a.indexmap().min_stride() == 1);
57 EXPECTS(ipiv.indexmap().min_stride() == 1);
58
59 int info = 0;
61#if defined(NDA_HAVE_DEVICE)
62 device::getri(a.extent(0), a.data(), get_ld(a), ipiv.data(), NULL, 0, info);
63#else
65#endif
66 } else {
67 // first call to get the optimal buffersize
68 using value_type = get_value_t<A>;
69 value_type bufferSize_T{};
70 f77::getri(a.extent(0), a.data(), get_ld(a), ipiv.data(), &bufferSize_T, -1, info);
71 int bufferSize = static_cast<int>(std::ceil(std::real(bufferSize_T)));
72
73 // allocate work buffer and perform actual library call
74 array<value_type, 1> work(bufferSize);
75#if defined(__has_feature)
76#if __has_feature(memory_sanitizer)
77 work = 0;
78#endif
79#endif
80 f77::getri(a.extent(0), a.data(), get_ld(a), ipiv.data(), work.data(), bufferSize, info);
81 }
82 return info;
83 }
84
85} // namespace nda::lapack
Provides definitions and type traits involving the different memory address spaces supported by nda.
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...
Provides concepts for the nda library.
Provides various convenient aliases and helper functions for nda::basic_array and nda::basic_array_vi...
Provides a custom runtime error class and macros to assert conditions and throw exceptions.
basic_array< ValueType, Rank, Layout, 'A', ContainerPolicy > array
Alias template of an nda::basic_array with an 'A' algebra.
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:181
int getri(A &&a, IPIV const &ipiv)
Interface to the LAPACK getri routine.
Definition getri.hpp:48
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:91
Provides a C++ interface for various LAPACK routines.
int get_ld(A const &a)
Get the leading dimension in LAPACK jargon of an nda::MemoryMatrix.
Definition tools.hpp:98
Macros used in the nda library.
Provides type traits for the nda library.