These subprograms perform the following computation, using the scalar alpha and vectors x and y:
alpha, x, y | Subprogram |
Short-precision real | SAXPY |
Long-precision real | DAXPY |
Short-precision complex | CAXPY |
Long-precision complex | ZAXPY |
Fortran | CALL SAXPY | DAXPY | CAXPY | ZAXPY (n, alpha, x, incx, y, incy) |
C and C++ | saxpy | daxpy | caxpy | zaxpy (n, alpha, x, incx, y, incy); |
PL/I | CALL SAXPY | DAXPY | CAXPY | ZAXPY (n, alpha, x, incx, y, incy); |
The computation is expressed as follows:
See reference [79]. If alpha or n is zero, no computation is performed. For CAXPY, intermediate results are accumulated in long precision.
None
n < 0
This example shows vectors x and y with positive strides.
N ALPHA X INCX Y INCY | | | | | | CALL SAXPY( 5 , 2.0 , X , 1 , Y , 2 ) X = (1.0, 2.0, 3.0, 4.0, 5.0) Y = (1.0, . , 1.0, . , 1.0, . , 1.0, . , 1.0)
Y = (3.0, . , 5.0, . , 7.0, . , 9.0, . , 11.0)
This example shows vectors x and y having strides of opposite signs. For y, which has negative stride, processing begins at element Y(5), which is 1.0.
N ALPHA X INCX Y INCY | | | | | | CALL SAXPY( 5 , 2.0 , X , 1 , Y , -1 ) X = (1.0, 2.0, 3.0, 4.0, 5.0) Y = (5.0, 4.0, 3.0, 2.0, 1.0)
Y = (15.0, 12.0, 9.0, 6.0, 3.0)
This example shows a vector, x, with 0 stride. Vector x is treated like a vector of length n, all of whose elements are the same as the single element in x.
N ALPHA X INCX Y INCY | | | | | | CALL SAXPY( 5 , 2.0 , X , 0 , Y , 1 ) X = (1.0) Y = (5.0, 4.0, 3.0, 2.0, 1.0)
Y = (7.0, 6.0, 5.0, 4.0, 3.0)
This example shows how SAXPY can be used to compute a scalar value. In this case, vectors x and y contain scalar values and the strides for both vectors are 0. The number of elements to be processed, n, is 1.
N ALPHA X INCX Y INCY | | | | | | CALL SAXPY( 1 , 2.0 , X , 0 , Y , 0 ) X = (1.0) Y = (5.0)
Y = (7.0)
This example shows how to use CAXPY, where vectors x and y contain complex numbers. In this case, vectors x and y have positive strides.
N ALPHA X INCX Y INCY | | | | | | CALL CAXPY( 3 ,ALPHA, X , 1 , Y , 2 ) ALPHA = (2.0, 3.0) X = ((1.0, 2.0), (2.0, 0.0), (3.0, 5.0)) Y = ((1.0, 1.0 ), . , (0.0, 2.0), . , (5.0, 4.0))
Y = ((-3.0, 8.0), . , (4.0, 8.0), . , (-4.0, 23.0))