HP MLIB User's Guide Vol. 1 7th Ed.

Chapter 2 Basic Vector Operations 67
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 y
i
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 x
i
= 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
Equivalent
SUBROUTINE SAXPY (N, A, X,INCX, Y,INCY)
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 - (N-1) * INCX
IF ( INCY .LT. 0 ) IY = 1 - (N-1) * INCY
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
where x and y are vectors 10 elements long stored in one-dimensional arrays X
and Y of dimension 20.
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 10-by-10 matrix from the 5th row. The matrix
is stored in a two-dimensional array B of dimension 20-by-21.
INTEGER*4 N
REAL*8 A,B(20,21)
N = 10
A = -3.0D0
CALL DAXPY (N,A,B(4,1),20,B(5,1),20)
y 2x y,+