IBM Books

Engineering and Scientific Subroutine Library for AIX Version 3 Release 3: Guide and Reference

SNAXPY and DNAXPY--Compute SAXPY or DAXPY N Times

These subprograms compute SAXPY or DAXPY, respectively, n times:

yi <-- yi + alphaixi    for i = 1, n

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.

Table 44. Data Types

a, x, y Subprogram
Short-precision real SNAXPY
Long-precision real DNAXPY

Syntax

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);

On Entry

n
is the number of SAXPY or DAXPY computations to be performed and the number of elements in vector a. Specified as: a fullword integer; n >= 0.

m
is the number of elements in vectors xi and yi for each SAXPY or DAXPY computation. Specified as: a fullword integer; m >= 0.

a
is the vector a of length n, containing the scalar values alphai, used in each computation of yi + alphaixi. Specified as: a one-dimensional array of (at least) length 1+(n-1)|inca|, containing numbers of the data type indicated in Table 44.

inca
is the stride for vector a. Specified as: a fullword integer. It can have any value.

x
is the vector (or matrix) x, containing the xi vectors of length m, used in the n computations of yi + alphaixi. Specified as: a one- or two-dimensional array of (at least) length (1+(n-1)(incxo)) + (m-1)|incxi|, containing numbers of the data type indicated in Table 44.

incxi
is the stride for x in the inner loop--that is, the stride identifying the elements in each vector xi. Specified as: a fullword integer. It can have any value.

incxo
is the stride for x in the outer loop--that is, the stride identifying each vector xi in x. Specified as: a fullword integer; incxo >= 0.

y
is the vector (or matrix) y, containing the yi vectors of length m, used in the n computations of yi + alphaixi. Specified as: a one- or two-dimensional array of (at least) length (1+(n-1)(incyo)) + (m-1)|incyi|, containing numbers of the data type indicated in Table 44.

incyi
is the stride for y in the inner loop--that is, the stride identifying the elements in each vector yi in y. Specified as: a fullword integer; incyi > 0 or incyi < 0.

incyo
is the stride for y in the outer loop--that is, the stride identifying each vector yi in y. Specified as: a fullword integer; incyo >= 0.

On Return

y
is the vector (or matrix) y, containing the yi vectors of length m, which contain the results of the n SAXPY or DAXPY computations, yi + alphaixi for i = 1, n. Returned as: a one- or two-dimensional array, containing numbers of the data type indicated in Table 44.

Note

Vector y must have no common elements with vector a or vector x; otherwise, results are unpredictable. See Concepts.

Function

The SAXPY or DAXPY computations:

y <-- y + alphax

are performed n times. This is expressed as follows:

yi <-- yi + alphaixi    for i = 1, n

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:

For i = 1, n:
alpha((i-1)inca+1)    for inca >= 0
alpha((i-n)inca+1)    for inca < 0
x((i-1)incxo+1)
y((i-1)incyo+1)

If m or n is 0, no computation is performed.

Error Conditions

Computational Errors

None

Input-Argument Errors
  1. n < 0
  2. m < 0
  3. incxo < 0
  4. incyi = 0
  5. incyo < 0

Example 1

This example shows vectors, contained in matrices, with the stride of the inner loops incxi and incyi equal to 1.

Call Statement and Input
             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 |
        |  .    .    .  |
        *               *

Output
        *                 *
        |  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 |
        |   .    .     .  |
        *                 *

Example 2

This example shows vectors, contained in matrices, with a stride of the inner loop incxi greater than 1.

Call Statement and Input
             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 |
        |  .    .    .  |
        *               *

Output

Y =(same as output Y in Example 1)

Example 3

This example shows vectors, contained in matrices, with a negative stride, incyi, for the inner loop.

Call Statement and Input
             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 |
        |  .    .    .  |
        *               *

Output
        *                 *
        | 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 |
        |   .    .     .  |
        *                 *

Example 4

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.

Call Statement and Input
             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 |
        |  .    .    .  |
        *               *

Output

Y =(same as output Y in Example 1)


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]