BLAS++ 2024.05.31
BLAS C++ API
Loading...
Searching...
No Matches
axpy.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_AXPY_HH
7#define BLAS_AXPY_HH
8
9#include "blas/util.hh"
10
11#include <limits>
12
13namespace blas {
14
15// =============================================================================
41
42template <typename TX, typename TY>
43void axpy(
44 int64_t n,
45 blas::scalar_type<TX, TY> alpha,
46 TX const *x, int64_t incx,
47 TY *y, int64_t incy )
48{
49 typedef blas::scalar_type<TX, TY> scalar_t;
50
51 // check arguments
52 blas_error_if( n < 0 );
53 blas_error_if( incx == 0 );
54 blas_error_if( incy == 0 );
55
56 // quick return
57 if (alpha == scalar_t(0))
58 return;
59
60 if (incx == 1 && incy == 1) {
61 // unit stride
62 for (int64_t i = 0; i < n; ++i) {
63 y[i] += alpha*x[i];
64 }
65 }
66 else {
67 // non-unit stride
68 int64_t ix = (incx > 0 ? 0 : (-n + 1)*incx);
69 int64_t iy = (incy > 0 ? 0 : (-n + 1)*incy);
70 for (int64_t i = 0; i < n; ++i) {
71 y[iy] += alpha * x[ix];
72 ix += incx;
73 iy += incy;
74 }
75 }
76}
77
78} // namespace blas
79
80#endif // #ifndef BLAS_AXPY_HH
void axpy(int64_t n, blas::scalar_type< TX, TY > alpha, TX const *x, int64_t incx, TY *y, int64_t incy)
Add scaled vector, .
Definition axpy.hh:43