GotoBlas2之IxAMAX

Blas的相关接口可以参考,同时要参考源码包中的reference文件夹,这个应该才是最重要的吧。

比如,在ICAMAX 中对incx的解释(来自网页,如下)

When working backward (incx < 0), each routine starts at the end of the
       vector and moves backward, as follows:

            x(1-incx * (n-1)), x(1-incx * (n-2)), ..., x(1)

但看reference文件夹icamaxf.f源码片段,不是这样的:

      icamaxf = 0
      if( n.lt.1 .or. incx.le.0 ) return

可知,当N<1或INCX<=0时,均返回0.

 

 

#include <stdio.h> #include <math.h> #include "gotoblas2.h" #pragma comment(lib,"libgoto2.lib") //FUNCTION IxAMAX (N , X, INCX) /* On Entry n is the number of elements in vector x. Specified as: an integer; n greater than or equal to 0. x is the vector x of length n. Specified as: a one-dimensional array of (at least) length 1+(n-1)|incx|, containing numbers of the data type indicated in Table 1. incx is the stride for vector x. Specified as: an integer. It can have any value. On Return Function value is the position i of the element in the array, where: If incx greater than 0, i is the position of the first occurrence. If incx <= 0 or n<=0,return 0. Notes Declare the ISAMAX, IDAMAX, ICAMAX, and IZAMAX functions in your program as returning an integer value Example 1 This example shows a vector, x, with a stride of 1. Function Reference and Input: N X INCX | | | IMAX = ISAMAX( 9 , X , 1 ) X = (1.0, 2.0, 7.0, -8.0, -5.0, -10.0, -9.0, 10.0, 6.0) Output: IMAX = 6 Example 2 This example shows a vector, x, with a stride greater than 1. Function Reference and Input: N X INCX | | | IMAX = ISAMAX( 5 , X , 2 ) X = (1.0, . , 7.0, . , -5.0, . , -9.0, . , 6.0) Output: IMAX = 4 ICAMAX and IZAMAX find the first element xk, where k is defined as the smallest index k, such that: |ak|+|bk| = max{|aj|+|bj| for j equal to 1, n} where xk equal to (ak, bk) Example 3 This example shows a vector, x, containing complex numbers and having a stride of 1. Function Reference and Input: N X INCX | | | IMAX = ICAMAX( 5 , X , 1 ) X = ((9.0 , 2.0) , (7.0 , -8.0) , (-5.0 , -10.0) , (-4.0 , 10.0), (6.0 , 3.0)) Output: IMAX = 2 */ int main(void) { float X1[9]={1.0, 2.0, 7.0, -8.0, -5.0, -10.0, -9.0, 10.0, 6.0}; float X2[9]={1.0, .0 , 7.0, .0 , -5.0, .0, -9.0, .0 , 6.0 }; myzcomplex_t X3[5]={{9.0 , 2.0}, {7.0,-8.0},{-5.0 , -10.0} , {-4.0 , 10.0}, {6.0 , 3.0}}; blasint IMAX; blasint N; blasint INCX; //blasint BLASFUNC(isamax)(blasint *, float *, blasint *); N=9; INCX=1; IMAX=ISAMAX( &N , X1 , &INCX ); printf(" The position is %d/n",(IMAX-1) * abs(INCX) + 1); N=5; INCX=2; IMAX = ISAMAX( &N , X2 , &INCX ); printf(" The position is %d/n",(IMAX-1) * abs(INCX) + 1); N=9; INCX=-1; IMAX = ISAMAX( &N , X2 , &INCX ); printf(" The position is %d/n",(IMAX-1) * abs(INCX) + 1); //0 当N<1或INCX<=0时,返回0 //blasint BLASFUNC(icamax)(blasint *, float *, blasint *); //blasint BLASFUNC(izamax)(blasint *, double *, blasint *); //Array of dimension (n-1) * |incx| + 1. //Return the first index of the maximum absolute value of vector // x. The vector x has length n and increment incx. N=5; INCX=1; IMAX = izamax( &N , (double *)X3 , &INCX ); printf(" The position is %d/n",(IMAX-1) * abs(INCX) + 1); //{7.0,-8.0} N=3; INCX=2; IMAX = izamax( &N , (double *)X3 , &INCX ); printf(" The position is %d/n",(IMAX-1) * abs(INCX) + 1); //{-5.0 , -10.0} return 0; } /*result The position is 6 The position is 7 The position is 0 The position is 2 The position is 3 */

你可能感兴趣的:(vector,function,Integer,reference,returning,Numbers)