TRIQS/nda 2.0.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 "../blas/tools.hpp"
17#include "../concepts.hpp"
18#include "../declarations.hpp"
19#include "../macros.hpp"
21#include "../traits.hpp"
22
23#include <algorithm>
24#include <cmath>
25#include <complex>
26#include <concepts>
27
28namespace nda::lapack {
29
66 template <BlasArrayCplx<2> A, BlasArrayFor<A, 2> B, BlasArrayRealFor<A, 1> W, BlasArrayFor<A, 1> W1 = vector_value_t<A>,
67 BlasArrayRealFor<A, 1> W2 = vector_fp_t<A>>
69 int hegv(A &&a, B &&b, W &&w, char jobz = 'V', int itype = 1, W1 &&work = vector_value_t<A>{}, W2 &&rwork = vector_fp_t<A>{}) { // NOLINT
70 // check the dimensions of the input/output arrays/views and resize if necessary
71 auto const [m, n] = a.shape();
72 EXPECTS(m == n);
73 EXPECTS(m == b.shape()[0]);
74 EXPECTS(n == b.shape()[1]);
76 resize_or_check_work_buffer(rwork, std::max(1l, 3 * n - 2));
77
78 // arrays/views must be LAPACK compatible
79 EXPECTS(a.indexmap().min_stride() == 1);
80 EXPECTS(b.indexmap().min_stride() == 1);
81 EXPECTS(w.indexmap().min_stride() == 1);
82
83 // check other input parameters for consistency
84 EXPECTS(itype == 1 or itype == 2 or itype == 3);
85 EXPECTS(jobz == 'V' or jobz == 'N');
86
87 // first call to get the optimal buffer size
88 auto tmp_lwork = get_value_t<A>{};
89 int info = 0;
90 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);
91 int lwork = static_cast<int>(std::ceil(std::real(tmp_lwork)));
92
93 // resize/check work buffer
94 resize_or_check_work_buffer(work, lwork);
95
96 // perform actual library call
97 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);
98
99 return info;
100 }
101
102} // 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.
Provides various traits and utilities for the BLAS interface.
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.
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:212
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:128
void resize_or_check_work_buffer(A &a, long min_size)
Resize or check the size of a 1D array/view.
Definition tools.hpp:207
vector< get_value_t< A >, heap< mem::get_addr_space< A > > > vector_value_t
Alias for an nda::vector with the same value type and address space as the given type.
Definition tools.hpp:161
vector< get_fp_t< A >, heap< mem::get_addr_space< A > > > vector_fp_t
Alias for an nda::vector with the same address space as the given type and its value type determined ...
Definition tools.hpp:170
static constexpr bool has_F_layout
Constexpr variable that is true if all given nda::Array types have nda::F_layout.
Definition tools.hpp:79
int hegv(A &&a, B &&b, W &&w, char jobz='V', int itype=1, W1 &&work=vector_value_t< A >{}, W2 &&rwork=vector_fp_t< A >{})
Interface to the LAPACK hegv routine.
Definition hegv.hpp:69
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.
Macros used in the nda library.
Provides type traits for the nda library.