These subprograms compute SAXPY or DAXPY, respectively, n times:
where each alphai is a scalar value, contained in the
vector a, and each xi and
yi are vectors, contained in vectors (or
matrices) x and y, respectively. For an
explanation of the SAXPY and DAXPY computations, see SAXPY, DAXPY, CAXPY, and ZAXPY--Multiply a Vector X by a Scalar, Add to a Vector Y, and Store in the Vector Y.
a, x, y | Subprogram |
Short-precision real | SNAXPY |
Long-precision real | DNAXPY |
Fortran | CALL SNAXPY | DNAXPY (n, m, a, inca, x, incxi, incxo, y, incyi, incyo) |
C and C++ | snaxpy | dnaxpy (n, m, a, inca, x, incxi, incxo, y, incyi, incyo); |
PL/I | CALL SNAXPY | DNAXPY (n, m, a, inca, x, incxi, incxo, y, incyi, incyo); |
Vector y must have no common elements with vector a or vector x; otherwise, results are unpredictable. See Concepts.
The SAXPY or DAXPY computations:
are performed n times. This is expressed as follows:
where each alphai is a scalar value, contained in the vector a, and each xi and yi are vectors, contained in vectors (or matrices) x and y, respectively.
Each computation of SAXPY or DAXPY on page SAXPY, DAXPY, CAXPY, and ZAXPY--Multiply a Vector X by a Scalar, Add to a Vector Y, and Store in the Vector Y uses the length of the xi and yi vectors, m, for its input argument, n. It also uses the strides for the inner loop, incxi and incyi, for its parameters incx and incy, respectively. See Function for a description of how the computation is done.
The outer loop of the SNAXPY or DNAXPY computation uses the strides of inca, incxo, and incyo to locate the elements in a and vectors in x and y for each i-th computation. These are:
If m or n is 0, no computation is performed.
None
This example shows vectors, contained in matrices, with the stride of the inner loops incxi and incyi equal to 1.
N M A INCA X INCXI INCXO Y INCYI INCYO | | | | | | | | | | CALL SNAXPY( 3 , 4 , A , 1 , X , 1 , 10 , Y , 1 , 5 ) A = (3.0, 2.0, 4.0)
* * | 1.0 4.0 3.0 | | 2.0 3.0 4.0 | | 3.0 2.0 2.0 | | 4.0 1.0 1.0 | X = | . . . | | . . . | | . . . | | . . . | | . . . | | . . . | * *
* * | 4.0 1.0 3.0 | | 3.0 2.0 4.0 | Y = | 2.0 3.0 2.0 | | 1.0 4.0 1.0 | | . . . | * *
* * | 7.0 9.0 15.0 | | 9.0 8.0 20.0 | Y = | 11.0 7.0 10.0 | | 13.0 6.0 5.0 | | . . . | * *
This example shows vectors, contained in matrices, with a stride of the inner loop incxi greater than 1.
N M A INCA X INCXI INCXO Y INCYI INCYO | | | | | | | | | | CALL SNAXPY( 3 , 4 , A , 1 , X , 2 , 10 , Y , 1 , 5 ) A = (3.0, 2.0, 4.0)
* * | 1.0 4.0 3.0 | | . . . | | 2.0 3.0 4.0 | | . . . | X = | 3.0 2.0 2.0 | | . . . | | 4.0 1.0 1.0 | | . . . | | . . . | | . . . | * *
* * | 4.0 1.0 3.0 | | 3.0 2.0 4.0 | Y = | 2.0 3.0 2.0 | | 1.0 4.0 1.0 | | . . . | * *
This example shows vectors, contained in matrices, with a negative stride, incyi, for the inner loop.
N M A INCA X INCXI INCXO Y INCYI INCYO | | | | | | | | | | CALL SNAXPY( 3 , 4 , A , 1 , X , 1 , 10 , Y , -1 , 5 ) A = (3.0, 2.0, 4.0)
* * | 1.0 4.0 3.0 | | 2.0 3.0 4.0 | | 3.0 2.0 2.0 | | 4.0 1.0 1.0 | X = | . . . | | . . . | | . . . | | . . . | | . . . | | . . . | * *
* * | 1.0 4.0 1.0 | | 2.0 3.0 2.0 | Y = | 3.0 2.0 4.0 | | 4.0 1.0 3.0 | | . . . | * *
* * | 13.0 6.0 5.0 | | 11.0 7.0 10.0 | Y = | 9.0 8.0 20.0 | | 7.0 9.0 15.0 | | . . . | * *
This example shows vectors, contained in matrices, with a negative stride, inca, for vector a. For vector a, processing begins at element A(5), which is 3.0.
N M A INCA X INCXI INCXO Y INCYI INCYO | | | | | | | | | | CALL SNAXPY( 3 , 4 , A , -2 , X , 1 , 10 , Y , 1 , 5 ) A = (4.0, . , 2.0, . , 3.0)
* * | 1.0 4.0 3.0 | | 2.0 3.0 4.0 | | 3.0 2.0 2.0 | | 4.0 1.0 1.0 | X = | . . . | | . . . | | . . . | | . . . | | . . . | | . . . | * *
* * | 4.0 1.0 3.0 | | 3.0 2.0 4.0 | Y = | 2.0 3.0 2.0 | | 1.0 4.0 1.0 | | . . . | * *