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-2023 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: Thomas Hahn, Miguel Morales, Nils Wentzell
16
22#pragma once
23
25#include "../concepts.hpp"
26#include "../declarations.hpp"
27#include "../exceptions.hpp"
28#include "../macros.hpp"
30#include "../traits.hpp"
31
32#include <algorithm>
33#include <cmath>
34#include <complex>
35#include <type_traits>
36
37namespace nda::lapack {
38
57 template <MemoryMatrix A, MemoryVector IPIV>
59 int getri(A &&a, IPIV const &ipiv) { // NOLINT (temporary views are allowed here)
60 static_assert(std::is_same_v<get_value_t<IPIV>, int>, "Error in nda::lapack::getri: Pivoting array must have elements of type int");
61 auto dm = std::min(a.extent(0), a.extent(1));
62
63 if (ipiv.size() < dm)
64 NDA_RUNTIME_ERROR << "Error in nda::lapack::getri: Pivot index array size " << ipiv.size() << " smaller than required size " << dm;
65
66 // must be lapack compatible
67 EXPECTS(a.indexmap().min_stride() == 1);
68 EXPECTS(ipiv.indexmap().min_stride() == 1);
69
70 int info = 0;
72#if defined(NDA_HAVE_DEVICE)
73 device::getri(a.extent(0), a.data(), get_ld(a), ipiv.data(), NULL, 0, info);
74#else
76#endif
77 } else {
78 // first call to get the optimal buffersize
79 using value_type = get_value_t<A>;
80 value_type bufferSize_T{};
81 f77::getri(a.extent(0), a.data(), get_ld(a), ipiv.data(), &bufferSize_T, -1, info);
82 int bufferSize = static_cast<int>(std::ceil(std::real(bufferSize_T)));
83
84 // allocate work buffer and perform actual library call
85 array<value_type, 1> work(bufferSize);
86#if defined(__has_feature)
87#if __has_feature(memory_sanitizer)
88 work = 0;
89#endif
90#endif
91 f77::getri(a.extent(0), a.data(), get_ld(a), ipiv.data(), work.data(), bufferSize, info);
92 }
93 return info;
94 }
95
96} // namespace nda::lapack
Provides definitions and type traits involving the different memory address spaces supported by nda.
A generic multi-dimensional array.
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.
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:192
int getri(A &&a, IPIV const &ipiv)
Interface to the LAPACK getri routine.
Definition getri.hpp:59
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:47
constexpr bool is_blas_lapack_v
Alias for nda::is_double_or_complex_v.
Definition traits.hpp:102
Provides a C++ interface for various LAPACK routines.
Macros used in the nda library.
Provides type traits for the nda library.