TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
dot.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 "../concepts.hpp"
15#include "../macros.hpp"
17#include "../traits.hpp"
18
19#ifndef NDA_HAVE_DEVICE
20#include "../device.hpp"
21#endif // NDA_HAVE_DEVICE
22
23namespace nda::blas {
24
29
46 template <MemoryVector X, MemoryVector Y>
48 auto dot(X const &x, Y const &y) {
49 // check the dimensions of the input/output arrays/views
50 EXPECTS(x.size() == y.size());
51
52 // perform actual library call
54#if defined(NDA_HAVE_DEVICE)
55 return device::dot(x.size(), x.data(), x.indexmap().strides()[0], y.data(), y.indexmap().strides()[0]);
56#else
58 return get_value_t<X>(0);
59#endif
60 } else {
61 return f77::dot(x.size(), x.data(), x.indexmap().strides()[0], y.data(), y.indexmap().strides()[0]);
62 }
63 }
64
81 template <MemoryVector X, MemoryVector Y>
83 auto dotc(X const &x, Y const &y) {
84 // check the dimensions of the input/output arrays/views
85 EXPECTS(x.size() == y.size());
86
87 // perform actual library call
88 if constexpr (!is_complex_v<get_value_t<X>>) {
89 return dot(x, y);
91#if defined(NDA_HAVE_DEVICE)
92 return device::dotc(x.size(), x.data(), x.indexmap().strides()[0], y.data(), y.indexmap().strides()[0]);
93#else
95 return get_value_t<X>(0);
96#endif
97 } else {
98 return f77::dotc(x.size(), x.data(), x.indexmap().strides()[0], y.data(), y.indexmap().strides()[0]);
99 }
100 }
101
103
104} // 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 concepts for the nda library.
Provides GPU and non-GPU specific functionality.
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:186
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:182
auto dot(X const &x, Y const &y)
Interface to the BLAS dot and dotu routine.
Definition dot.hpp:48
auto dotc(X const &x, Y const &y)
Interface to the BLAS dotc routine.
Definition dot.hpp:83
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...
Definition device.hpp:36
constexpr bool is_complex_v
Constexpr variable that is true if type T is a std::complex type.
Definition traits.hpp:65
constexpr bool is_blas_lapack_v
Alias for nda::is_double_or_complex_v.
Definition traits.hpp:92
Macros used in the nda library.
Provides type traits for the nda library.