BLAS++ 2024.05.31
BLAS C++ API
Loading...
Searching...
No Matches
iamax.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_IAMAX_HH
7#define BLAS_IAMAX_HH
8
9#include "blas/util.hh"
10
11#include <limits>
12
13namespace blas {
14
15// =============================================================================
32
33template <typename T>
34int64_t iamax(
35 int64_t n,
36 T const *x, int64_t incx )
37{
38 typedef real_type<T> real_t;
39
40 // check arguments
41 blas_error_if( n < 0 ); // standard BLAS returns, doesn't fail
42 blas_error_if( incx <= 0 ); // standard BLAS returns, doesn't fail
43
44 // todo: check NAN
45 real_t result = -1;
46 int64_t index = -1;
47 if (incx == 1) {
48 // unit stride
49 for (int64_t i = 0; i < n; ++i) {
50 real_t tmp = abs1( x[i] );
51 if (tmp > result) {
52 result = tmp;
53 index = i;
54 }
55 }
56 }
57 else {
58 // non-unit stride
59 int64_t ix = 0;
60 for (int64_t i = 0; i < n; ++i) {
61 real_t tmp = abs1( x[ix] );
62 if (tmp > result) {
63 result = tmp;
64 index = i;
65 }
66 ix += incx;
67 }
68 }
69 return index;
70}
71
72} // namespace blas
73
74#endif // #ifndef BLAS_IAMAX_HH
int64_t iamax(int64_t n, T const *x, int64_t incx)
Definition iamax.hh:34