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