<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
asum.hpp
Go to the documentation of this file.
1
3//
4// Copyright (c) 2017-2021, University of Tennessee. All rights reserved.
5// Copyright (c) 2021-2023, University of Colorado Denver. All rights reserved.
6//
7// This file is part of <T>LAPACK.
8// <T>LAPACK is free software: you can redistribute it and/or modify it under
9// the terms of the BSD 3-Clause license. See the accompanying LICENSE file.
10
11#ifndef TLAPACK_BLAS_ASUM_HH
12#define TLAPACK_BLAS_ASUM_HH
13
15
16namespace tlapack {
17
26template <TLAPACK_VECTOR vector_t, disable_if_allow_optblas_t<vector_t> = 0>
27auto asum(vector_t const& x)
28{
29 using T = type_t<vector_t>;
30 using idx_t = size_type<vector_t>;
31 using real_t = real_type<T>;
32
33 // constants
34 const idx_t n = size(x);
35
36 real_t result = 0;
37 for (idx_t i = 0; i < n; ++i)
38 result += abs1(x[i]);
39
40 return result;
41}
42
43#ifdef TLAPACK_USE_LAPACKPP
44
45template <TLAPACK_LEGACY_VECTOR vector_t,
46 enable_if_allow_optblas_t<vector_t> = 0>
47auto asum(vector_t const& x)
48{
49 // Legacy objects
50 auto x_ = legacy_vector(x);
51
52 // Constants to forward
53 const auto& n = x_.n;
54
55 return ::blas::asum(n, x_.ptr, x_.inc);
56}
57
58#endif
59
60} // namespace tlapack
61
62#endif // #ifndef TLAPACK_BLAS_ASUM_HH
constexpr real_type< T > abs1(const T &x)
1-norm absolute value, |Re(x)| + |Im(x)|
Definition utils.hpp:133
#define TLAPACK_LEGACY_VECTOR
Macro for tlapack::concepts::LegacyVector compatible with C++17.
Definition concepts.hpp:954
auto asum(vector_t const &x)
Vector 1-norm: .
Definition asum.hpp:27
typename traits::real_type_traits< Types..., int >::type real_type
The common real type of the list of types.
Definition scalar_type_traits.hpp:113