TRIQS/nda 2.0.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
ger.hpp
Go to the documentation of this file.
1// Copyright (c) 2019--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 "./tools.hpp"
15#include "../concepts.hpp"
16#include "../device.hpp"
19#include "../macros.hpp"
21#include "../traits.hpp"
22
23namespace nda::blas {
24
29
53 template <BlasArray<1> X, BlasArrayFor<X, 1> Y, BlasArrayFor<X, 2> A>
54 void ger(get_value_t<X> alpha, X const &x, Y const &y, A &&a) { // NOLINT (temporary views are allowed here)
55 // for C-layout arrays/views, call ger with the transpose and swap x and y
56 if constexpr (has_C_layout<A>) {
57 ger(alpha, y, x, transpose(a));
58 return;
59 }
60
61 // check the dimensions of the input/output arrays/views
62 auto const [m, n] = a.shape();
63 EXPECTS(m == x.size());
64 EXPECTS(n == y.size());
65
66 // arrays/views must be BLAS compatible
67 EXPECTS(a.indexmap().min_stride() == 1);
68
69 // perform actual library call
71 device::ger(m, n, alpha, x.data(), x.indexmap().strides()[0], y.data(), y.indexmap().strides()[0], a.data(), get_ld(a));
72 } else {
73 f77::ger(m, n, alpha, x.data(), x.indexmap().strides()[0], y.data(), y.indexmap().strides()[0], a.data(), get_ld(a));
74 }
75 }
76
99 template <BlasArray<1> X, BlasArrayFor<X, 1> Y, BlasArrayFor<X, 2> A>
100 requires(has_F_layout<A>)
101 void gerc(get_value_t<X> alpha, X const &x, Y const &y, A &&a) { // NOLINT (temporary views are allowed here)
102 // check the dimensions of the input/output arrays/views
103 auto const [m, n] = a.shape();
104 EXPECTS(m == x.size());
105 EXPECTS(n == y.size());
106
107 // arrays/views must be BLAS compatible
108 EXPECTS(a.indexmap().min_stride() == 1);
109
110 // perform actual library call
111 if constexpr (!is_complex_v<get_value_t<X>>) {
112 return ger(alpha, x, y, a);
114 device::gerc(m, n, alpha, x.data(), x.indexmap().strides()[0], y.data(), y.indexmap().strides()[0], a.data(), get_ld(a));
115 } else {
116 f77::gerc(m, n, alpha, x.data(), x.indexmap().strides()[0], y.data(), y.indexmap().strides()[0], a.data(), get_ld(a));
117 }
118 }
119
121
122} // namespace nda::blas
Provides definitions and type traits involving the different memory address spaces supported by nda.
Provides a C++ interface for various BLAS routines.
Provides various traits and utilities for the BLAS interface.
Provides concepts for the nda library.
Provides GPU and non-GPU specific functionality.
auto transpose(A &&a)
Transpose the memory layout of an nda::MemoryArray or an nda::expr_call.
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
static constexpr bool has_C_layout
Constexpr variable that is true if all given nda::Array types have nda::C_layout.
Definition tools.hpp:89
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
void gerc(get_value_t< X > alpha, X const &x, Y const &y, A &&a)
Interface to the BLAS/cuBLAS gerc routine.
Definition ger.hpp:101
void ger(get_value_t< X > alpha, X const &x, Y const &y, A &&a)
Interface to the BLAS/cuBLAS ger and geru routine.
Definition ger.hpp:54
static constexpr bool have_device_compatible_addr_space
Constexpr variable that is true if all given types have an address space compatible with Device.
constexpr bool is_complex_v
Constexpr variable that is true if type T is a std::complex type.
Definition traits.hpp:65
Provides definitions of various layout policies.
Provides functions to transform the memory layout of an nda::basic_array or nda::basic_array_view.
Macros used in the nda library.
Provides type traits for the nda library.