BLAS++ 2024.05.31
BLAS C++ API
Loading...
Searching...
No Matches
asum.hh
1// Copyright (c) 2017-2023, University of Tennessee. All rights reserved.
2// SPDX-License-Identifier: BSD-3-Clause
3// This program is free software: you can redistribute it and/or modify it under
4// the terms of the BSD 3-Clause license. See the accompanying LICENSE file.
5
6#ifndef BLAS_ASUM_HH
7#define BLAS_ASUM_HH
8
9#include "blas/util.hh"
10
11#include <limits>
12
13namespace blas {
14
15// =============================================================================
32
33template <typename T>
34real_type<T>
36 int64_t n,
37 T const *x, int64_t incx )
38{
39 typedef real_type<T> real_t;
40
41 // check arguments
42 blas_error_if( n < 0 ); // standard BLAS returns, doesn't fail
43 blas_error_if( incx <= 0 ); // standard BLAS returns, doesn't fail
44
45 real_t result = 0;
46 if (incx == 1) {
47 // unit stride
48 for (int64_t i = 0; i < n; ++i) {
49 result += abs1( x[i] );
50 }
51 }
52 else {
53 // non-unit stride
54 int64_t ix = 0;
55 for (int64_t i = 0; i < n; ++i) {
56 result += abs1( x[ix] );
57 ix += incx;
58 }
59 }
60 return result;
61}
62
63} // namespace blas
64
65#endif // #ifndef BLAS_ASUM_HH
real_type< T > asum(int64_t n, T const *x, int64_t incx)
Definition asum.hh:35