28namespace nda::linalg {
38 template <Matrix A, Vector X, MemoryVector Y>
40 void gemv_generic(
auto alpha, A
const &a, X
const &x,
auto beta, Y &&y) {
42 auto const [m, n] = a.shape();
43 EXPECTS(n == x.size());
44 EXPECTS(m == y.size());
47 for (
int i = 0; i < m; ++i) {
49 for (
int j = 0; j < n; ++j) y(i) += alpha * a(i, j) * x(j);
55 template <
typename T,
typename CP, Vector X>
56 decltype(
auto) get_gemv_vector(X &&x) {
57 if constexpr (std::is_same_v<get_value_t<X>, T> and MemoryVector<X>) {
58 return std::forward<X>(x);
66 template <
typename T,
typename CP, Matrix A>
67 decltype(
auto) get_gemv_matrix(A &&a) {
68 using namespace blas_lapack;
69 if constexpr (
requires {
get_array(a); } and std::is_same_v<get_value_t<A>, T>) {
70 if constexpr (MemoryMatrix<A> or (is_conj_array_expr<A> and has_C_layout<A>)) {
71 return std::forward<A>(a);
81 template <Matrix A, Vector X, MemoryVector Y>
82 void make_gemv_call(A
const &a, X
const &x, Y &y) {
128 template <Matrix A, Vector X>
132 using value_t =
decltype(a(0, 0) * x(0));
137 auto res = return_t(a.shape()[0]);
138#if defined(__has_feature)
139#if __has_feature(memory_sanitizer)
146 auto &&a_mat = detail::get_gemv_matrix<value_t, cont_pol>(a);
147 auto &&x_vec = detail::get_gemv_vector<value_t, cont_pol>(x);
150 detail::make_gemv_call(a_mat, x_vec, res);
152 detail::gemv_generic(1, a, x, 0, res);
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 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.
Provides a generic interface to the BLAS/cuBLAS gemv routine.
decltype(auto) make_regular(A &&a)
Make a given object regular.
basic_array< ValueType, 1, C_layout, 'V', ContainerPolicy > vector
Alias template of an nda::basic_array with rank 1 and a 'V' algebra.
basic_array< ValueType, 2, Layout, 'M', ContainerPolicy > matrix
Alias template of an nda::basic_array with rank 2 and an 'M' algebra.
MemoryArray decltype(auto) get_array(A &&a)
Get the underlying array of a conjugate lazy expression or return the array itself in case it is an n...
void gemv(get_value_t< A > alpha, A const &a, X const &x, get_value_t< A > beta, Y &&y)
Interface to the BLAS/cuBLAS gemv routine.
auto matvecmul(A const &a, X const &x)
Compute the matrix-vector product of an nda::Matrix and an nda::Vector object.
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.
heap_basic< mem::mallocator< AdrSp > > heap
Alias template of the nda::heap_basic policy using an nda::mem::mallocator.
constexpr bool is_blas_lapack_v
Constexpr variable that is true if type T is either of type 'float', double, std::complex<float>' or ...
Provides definitions of various layout policies.
Defines various memory handling policies.
Provides type traits for the nda library.