TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
hegv.hpp
Go to the documentation of this file.
1// Copyright (c) 2024--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 "../basic_array.hpp"
16#include "../concepts.hpp"
17#include "../declarations.hpp"
18#include "../macros.hpp"
20#include "../traits.hpp"
21
22#include <algorithm>
23#include <cmath>
24#include <complex>
25#include <concepts>
26
27namespace nda::lapack {
28
56 template <MemoryMatrix A, MemoryMatrix B, MemoryVector W>
57 requires(mem::have_host_compatible_addr_space<A, B> and std::same_as<std::complex<double>, get_value_t<A>> and have_same_value_type_v<A, B>
58 and std::same_as<double, get_value_t<W>>)
59 int hegv(A &&a, B &&b, W &&w, char jobz = 'V', int itype = 1) { // NOLINT (temporary views are allowed here)
60 static_assert(has_F_layout<A> and has_F_layout<B>, "Error in nda::lapack::hegv: A and B must have Fortran layout");
61
62 // check the dimensions of the input/output arrays/views and resize if necessary
63 auto const [m, n] = a.shape();
64 EXPECTS(m == n);
65 EXPECTS(m == b.shape()[0]);
66 EXPECTS(n == b.shape()[1]);
68
69 // arrays/views must be LAPACK compatible
70 EXPECTS(a.indexmap().min_stride() == 1);
71 EXPECTS(b.indexmap().min_stride() == 1);
72 EXPECTS(w.indexmap().min_stride() == 1);
73
74 // check other input parameters for consistency
75 EXPECTS(itype == 1 or itype == 2 or itype == 3);
76 EXPECTS(jobz == 'V' or jobz == 'N');
77
78 // first call to get the optimal buffer size
79 array<double, 1> rwork(std::max(1l, 3 * n - 2));
80 std::complex<double> tmp_lwork{};
81 int info = 0;
82 lapack::f77::hegv(itype, jobz, 'U', n, a.data(), get_ld(a), b.data(), get_ld(b), w.data(), &tmp_lwork, -1, rwork.data(), info);
83 int lwork = static_cast<int>(std::ceil(std::real(tmp_lwork)));
84
85 // allocate work buffer and perform actual library call
86 array<std::complex<double>, 1> work(lwork);
87 lapack::f77::hegv(itype, jobz, 'U', n, a.data(), get_ld(a), b.data(), get_ld(b), w.data(), work.data(), lwork, rwork.data(), info);
88
89 return info;
90 }
91
92} // namespace nda::lapack
Provides definitions and type traits involving the different memory address spaces supported by nda.
Provides the generic class for arrays.
Provides basic functions to create and manipulate arrays and views.
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...
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.
basic_array< ValueType, Rank, Layout, 'A', ContainerPolicy > array
Alias template of an nda::basic_array with an 'A' algebra.
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
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:182
int hegv(A &&a, B &&b, W &&w, char jobz='V', int itype=1)
Interface to the LAPACK hegv routine.
Definition hegv.hpp:59
static constexpr bool have_host_compatible_addr_space
Constexpr variable that is true if all given types have an address space compatible with Host.
Provides a C++ interface for various LAPACK routines.
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 has_F_layout
Constexpr variable that is true if the given nda::Array type has nda::F_layout.
Definition tools.hpp:73
Macros used in the nda library.
Provides type traits for the nda library.