i?amax
实数向量返回最大绝对值的索引值,复数向量返回实部绝对值和虚部绝对值之和的最大值索引值。
接口定义
C interface:
CBLAS_INDEX cblas_isamax(const BLASINT n, const float *x, const BLASINT incx);
CBLAS_INDEX cblas_idamax(const BLASINT n, const double *x, const BLASINT incx);
CBLAS_INDEX cblas_icamax(const BLASINT n, const void *x, const BLASINT incx);
CBLAS_INDEX cblas_izamax(const BLASINT n, const void *x, const BLASINT incx);
Fortran interface:
INDEX = ISAMAX(N, X, INCX)
INDEX = IDAMAX(N, X, INCX)
INDEX = ICAMAX(N, X, INCX)
INDEX = IZAMAX(N, X, INCX)
参数
参数名 |
类型 |
描述 |
输入/输出 |
|---|---|---|---|
n |
整型数 |
表示x向量的元素个数。 |
输入 |
x |
|
向量x,向量规模至少是(1+(n-1)*abs(incX))。 |
输入 |
incx |
整型数 |
表示x向量增长步长。 |
输入 |
返回值
实数向量返回最大绝对值的索引值,复数向量返回实部绝对值和虚部绝对值之和的最大值索引值。CBLAS_INDEX类型。
依赖
#include "kblas.h"
示例
C interface:
1 2 3 4 5 6 7 8 9 10 11 | int n = 5, incx = 1; int res; /** * X: 0.340188, -0.105617, 0.283099, 0.298440, 0.411647 */ float x[5] = {0.340188, -0.105617, 0.283099, 0.298440, 0.411647}; res = cblas_isamax(n, x, incx); /** * Output: 4 */ |
Fortran interface:
INTEGER :: N=5
INTEGER :: INCX=1
INTEGER :: INDEX
REAL(4) :: X(5)
DATA X/0.340188, -0.105617, 0.283099, 0.298440, 0.411647/
EXTERNAL ISAMAX
INDEX=ISAMAX(N, X, INCX)
* Output : 5
在C语言中,index是从0开始,在Fortran语言中,index是从1开始,因此在该Fortran用例中最大绝对值是第五个元素,所以会返回最大绝对值的索引值为5。