TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
scal.hpp
Go to the documentation of this file.
1// Copyright (c) 2023 Simons Foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0.txt
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Authors: Miguel Morales, Nils Wentzell
16
17/**
18 * @file
19 * @brief Provides a generic interface to the BLAS `scal` routine.
20 */
21
22#pragma once
23
24#include "./interface/cxx_interface.hpp"
25#include "./tools.hpp"
26#include "../concepts.hpp"
27#include "../device.hpp"
28#include "../mem/address_space.hpp"
29#include "../traits.hpp"
30
31namespace nda::blas {
32
33 /**
34 * @ingroup linalg_blas
35 * @brief Interface to the BLAS `scal` routine.
36 *
37 * @details Scales a vector by a constant. This function calculates
38 * \f[
39 * \mathbf{x} \leftarrow \alpha \mathbf{x} ;,
40 * \f]
41 * where \f$ \alpha \f$ is a scalar constant and \f$ \mathbf{x} \f$ is a vector.
42 *
43 * @tparam X nda::MemoryVector or a conjugate array expression.
44 * @param alpha Input scalar.
45 * @param x Input/Output vector to be scaled.
46 */
47 template <typename X>
48 requires(MemoryVector<X> or is_conj_array_expr<X>)
49 void scal(get_value_t<X> alpha, X &&x) { // NOLINT (temporary views are allowed here)
50 static_assert(is_blas_lapack_v<get_value_t<X>>, "Error in nda::blas::scal: Value type of vector is incompatible with blas");
51
52 if constexpr (mem::on_host<X>) {
53 f77::scal(x.size(), alpha, x.data(), x.indexmap().strides()[0]);
54 } else {
55#if defined(NDA_HAVE_DEVICE)
56 device::scal(x.size(), alpha, x.data(), x.indexmap().strides()[0]);
57#else
59#endif
60 }
61 }
62
63} // namespace nda::blas
void scal(get_value_t< X > alpha, X &&x)
Interface to the BLAS scal routine.
Definition scal.hpp:49
void compile_error_no_gpu()
Trigger a compilation error in case GPU specific functionality is used without configuring the projec...
Definition device.hpp:47