TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
geqp3.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"
15#include "../concepts.hpp"
16#include "../declarations.hpp"
17#include "../exceptions.hpp"
18#include "../macros.hpp"
20#include "../traits.hpp"
21
22#include <algorithm>
23#include <cmath>
24#include <complex>
25#include <type_traits>
26
27namespace nda::lapack {
28
53 template <MemoryMatrix A, MemoryVector JPVT, MemoryVector TAU>
56 int geqp3(A &&a, JPVT &&jpvt, TAU &&tau) { // NOLINT (temporary views are allowed here)
57 static_assert(has_F_layout<A>, "Error in nda::lapack::geqp3: C order not supported");
58 static_assert(std::is_same_v<get_value_t<JPVT>, int>, "Error in nda::lapack::geqp3: Pivoting array must have elements of type int");
59 static_assert(mem::have_host_compatible_addr_space<A, JPVT, TAU>, "Error in nda::lapack::geqp3: Only CPU is supported");
60
61 auto [m, n] = a.shape();
62 EXPECTS(tau.size() >= std::min(m, n));
63
64 // must be lapack compatible
65 EXPECTS(a.indexmap().min_stride() == 1);
66 EXPECTS(jpvt.indexmap().min_stride() == 1);
67 EXPECTS(tau.indexmap().min_stride() == 1);
68
69 // first call to get the optimal buffersize
70 using value_type = get_value_t<A>;
71 value_type bufferSize_T{};
72 int info = 0;
73 array<double, 1> rwork(2 * n);
74 lapack::f77::geqp3(m, n, a.data(), get_ld(a), jpvt.data(), tau.data(), &bufferSize_T, -1, rwork.data(), info);
75 int bufferSize = static_cast<int>(std::ceil(std::real(bufferSize_T)));
76
77 // allocate work buffer and perform actual library call
78 nda::array<value_type, 1> work(bufferSize);
79 lapack::f77::geqp3(m, n, a.data(), get_ld(a), jpvt.data(), tau.data(), work.data(), bufferSize, rwork.data(), info);
80 jpvt -= 1; // Shift to 0-based indexing
81
82 if (info) NDA_RUNTIME_ERROR << "Error in nda::lapack::geqp3: info = " << info;
83 return info;
84 }
85
86} // namespace nda::lapack
Provides definitions and type traits involving the different memory address spaces supported by nda.
Provides the generic class for arrays.
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.
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:185
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 geqp3(A &&a, JPVT &&jpvt, TAU &&tau)
Interface to the LAPACK geqp3 routine.
Definition geqp3.hpp:56
static constexpr bool have_host_compatible_addr_space
Constexpr variable that is true if all given types have an address space compatible with Host.
static constexpr bool have_compatible_addr_space
Constexpr variable that is true if all given types have compatible address spaces.
static constexpr bool on_host
Constexpr variable that is true if all given types have a Host address space.
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
static constexpr bool has_F_layout
Constexpr variable that is true if the given nda::Array type has a Fortran memory layout.
Definition tools.hpp:55
Macros used in the nda library.
Provides type traits for the nda library.