BLAS++ 2024.05.31
BLAS C++ API
Loading...
Searching...
No Matches
copy.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_COPY_HH
7#define BLAS_COPY_HH
8
9#include "blas/util.hh"
10
11#include <limits>
12
13namespace blas {
14
15// =============================================================================
38
39template <typename TX, typename TY>
40void copy(
41 int64_t n,
42 TX const *x, int64_t incx,
43 TY *y, int64_t incy )
44{
45 // check arguments
46 blas_error_if( n < 0 );
47 blas_error_if( incx == 0 );
48 blas_error_if( incy == 0 );
49
50 if (incx == 1 && incy == 1) {
51 // unit stride
52 for (int64_t i = 0; i < n; ++i) {
53 y[i] = x[i];
54 }
55 }
56 else {
57 // non-unit stride
58 int64_t ix = (incx > 0 ? 0 : (-n + 1)*incx);
59 int64_t iy = (incy > 0 ? 0 : (-n + 1)*incy);
60 for (int64_t i = 0; i < n; ++i) {
61 y[iy] = x[ix];
62 ix += incx;
63 iy += incy;
64 }
65 }
66}
67
68} // namespace blas
69
70#endif // #ifndef BLAS_COPY_HH
void copy(int64_t n, TX const *x, int64_t incx, TY *y, int64_t incy)
Copy vector, .
Definition copy.hh:40