BLAS++ 2024.05.31
BLAS C++ API
Loading...
Searching...
No Matches
swap.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_SWAP_HH
7#define BLAS_SWAP_HH
8
9#include "blas/util.hh"
10
11#include <limits>
12
13namespace blas {
14
15// =============================================================================
38
39template <typename TX, typename TY>
40void swap(
41 int64_t n,
42 TX *x, int64_t incx,
43 TY *y, int64_t incy )
44{
45 using std::swap;
46
47 // check arguments
48 blas_error_if( n < 0 ); // standard BLAS returns, doesn't fail
49 blas_error_if( incx == 0 ); // standard BLAS doesn't detect inc[xy] == 0
50 blas_error_if( incy == 0 );
51
52 if (incx == 1 && incy == 1) {
53 // unit stride
54 for (int64_t i = 0; i < n; ++i) {
55 swap( x[i], y[i] );
56 }
57 }
58 else {
59 // non-unit stride
60 int64_t ix = (incx > 0 ? 0 : (-n + 1)*incx);
61 int64_t iy = (incy > 0 ? 0 : (-n + 1)*incy);
62 for (int64_t i = 0; i < n; ++i) {
63 swap( x[ix], y[iy] );
64 ix += incx;
65 iy += incy;
66 }
67 }
68}
69
70} // namespace blas
71
72#endif // #ifndef BLAS_SWAP_HH
void swap(int64_t n, float *x, int64_t incx, float *y, int64_t incy, blas::Queue &queue)
GPU device, float version.
Definition device_swap.cc:67