24#ifndef NDA_HAVE_DEVICE
34namespace nda::lapack {
64 template <MemoryMatrix A, MemoryVector S, MemoryMatrix U, MemoryMatrix VT>
66 and std::same_as<double, get_value_t<S>>)
67 int gesvd(A &&a, S &&s, U &&u, VT &&vt) {
69 "Error in nda::lapack::gesvd: Matrix layouts have to be the same");
72 auto const [m, n] = a.shape();
73 auto const k = std::min(m, n);
88 EXPECTS(a.indexmap().min_stride() == 1);
89 EXPECTS(s.indexmap().min_stride() == 1);
90 EXPECTS(u.indexmap().min_stride() == 1);
91 EXPECTS(vt.indexmap().min_stride() == 1);
94 auto gesvd_call = []<
typename... Ts>(Ts &&...args) {
96#if defined(NDA_HAVE_DEVICE)
97 lapack::device::gesvd(std::forward<Ts>(args)...);
102 lapack::f77::gesvd(std::forward<Ts>(args)...);
108 value_type tmp_lwork{};
112 gesvd_call(
'A',
'A', n, m, a.data(),
get_ld(a), s.data(), vt.data(),
get_ld(vt), u.data(),
get_ld(u), &tmp_lwork, -1, rwork.data(), info);
114 gesvd_call(
'A',
'A', m, n, a.data(),
get_ld(a), s.data(), u.data(),
get_ld(u), vt.data(),
get_ld(vt), &tmp_lwork, -1, rwork.data(), info);
116 int lwork =
static_cast<int>(std::ceil(std::real(tmp_lwork)));
121 gesvd_call(
'A',
'A', n, m, a.data(),
get_ld(a), s.data(), vt.data(),
get_ld(vt), u.data(),
get_ld(u), work.
data(), lwork, rwork.data(), info);
123 gesvd_call(
'A',
'A', m, n, a.data(),
get_ld(a), s.data(), u.data(),
get_ld(u), vt.data(),
get_ld(vt), work.
data(), lwork, rwork.data(), info);
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...
Provides GPU and non-GPU specific functionality.
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.
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.
int gesvd(A &&a, S &&s, U &&u, VT &&vt)
Interface to the LAPACK gesvd routine.
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...
constexpr bool is_blas_lapack_v
Alias for nda::is_double_or_complex_v.
Provides a C++ interface for various LAPACK routines.
static constexpr bool has_C_layout
Constexpr variable that is true if the given nda::Array type has nda::C_layout.
int get_ld(A const &a)
Get the leading dimension of an nda::MemoryArray with rank 1 or 2 for BLAS/LAPACK calls.
Provides definitions of various layout policies.
Macros used in the nda library.
Defines various memory handling policies.
Provides type traits for the nda library.