Elementary vector operation | SAXPY/DAXPY/CAXPY/CAXPYC/ZAXPY/ZAXPYC | |
|
| Use incy = 1 if the vector y is stored contiguously in |
|
| array y; that is, if yi is stored in y(i). Refer to “BLAS |
|
| Indexing Conventions” in the introduction to this |
|
| chapter. |
Output | y | If n ≤ 0 or a = 0, then y is unchanged. Otherwise, ax+y |
|
| overwrites the input. |
Notes | If incx = 0, then xi | = x(1) for all i. |
| The result is unspecified if incy = 0 or if x and y overlap such that any element | |
| of x shares a memory location with any element of y. |
Fortran | SUBROUTINE SAXPY (N, A, X,INCX, Y,INCY) |
Equivalent | REAL*4 X(*),Y(*) |
| IF ( N .LE. 0 ) RETURN |
| IF ( A .EQ. 0.0 ) RETURN |
| IX = 1 |
| IY = 1 |
| IF ( INCX .LT. 0 ) IX = 1 - |
| IF ( INCY .LT. 0 ) IY = 1 - |
| DO 10 I = 1, N |
| Y(IY) = A * X(IX) + Y(IY) |
| IX = IX + INCX |
| IY = IY + INCY |
| 10 CONTINUE |
| RETURN |
| END |
Example 1 Compute the REAL*8 elementary vector operation
y← 2x + y,
where x and y are vectors 10 elements long stored in
INTEGER*4 N,INCX,INCY
REAL*8 | A,X(20),Y(20) | |
N = | 10 |
|
A = | 2.0D0 |
|
INCX = 1
INCY = 1
CALL DAXPY (N,A,X,INCX,Y,INCY)
Example 2 Subtract 3 times the 4th row of a
INTEGER*4 | N | |
REAL*8 | A,B(20,21) | |
N = | 10 |
|
A = |
|
CALL DAXPY (N,A,B(4,1),20,B(5,1),20)
Chapter 2 Basic Vector Operations 67