These subprograms interchange the elements of vectors x and y:
x, y | Subprogram |
Short-precision real | SSWAP |
Long-precision real | DSWAP |
Short-precision complex | CSWAP |
Long-precision complex | ZSWAP |
Fortran | CALL SSWAP | DSWAP | CSWAP | ZSWAP (n, x, incx, y, incy) |
C and C++ | sswap | dswap | cswap | zswap (n, x, incx, y, incy); |
PL/I | CALL SSWAP | DSWAP | CSWAP | ZSWAP (n, x, incx, y, incy); |
The elements of vectors x and y are interchanged as follows:
See reference [79]. If n is 0, no elements are interchanged.
None
n < 0
This example shows vectors x and y with positive strides.
N X INCX Y INCY | | | | | CALL SSWAP( 5 , X , 1 , Y , 2 ) X = (1.0, 2.0, 3.0, 4.0, 5.0) Y = (-1.0, . , -2.0, . , -3.0, . , -4.0, . , -5.0)
X = (-1.0, -2.0, -3.0, -4.0, -5.0) Y = (1.0, . , 2.0, . , 3.0, . , 4.0, . , 5.0)
This example shows how to obtain output vectors x and y that are reverse copies of the input vectors y and x. You must specify strides with the same absolute value, but with opposite signs. For y, which has negative stride, processing begins at element Y(5), which is -5.0, and the results of the swap are stored beginning at the same element.
N X INCX Y INCY | | | | | CALL SSWAP( 5 , X , 1 , Y , -1 ) X = (1.0, 2.0, 3.0, 4.0, 5.0) Y = (-1.0, -2.0, -3.0, -4.0, -5.0)
X = (-5.0, -4.0, -3.0, -2.0, -1.0) Y = (5.0, 4.0, 3.0, 2.0, 1.0)
This example shows how SSWAP can be used to interchange scalar values in vectors x and y by specifying 0 strides and the number of elements to be processed as 1.
N X INCX Y INCY | | | | | CALL SSWAP( 1 , X , 0 , Y , 0 ) X = (1.0) Y = (-4.0)
X = (-4.0) Y = (1.0)
This example shows vectors x and y, containing complex numbers and having positive strides.
N X INCX Y INCY | | | | | CALL CSWAP( 4 , X , 1 , Y , 2 ) X = ((1.0, 6.0), (2.0, 7.0), (3.0, 8.0), (4.0, 9.0)) Y = ((-1.0, -1.0), . , (-2.0, -2.0), . , (-3.0, -3.0), . , (-4.0, -4.0))
X = ((-1.0, -1.0), (-2.0, -2.0), (-3.0, -3.0), (-4.0, -4.0)) Y = ((1.0, 6.0), . , (2.0, 7.0), . , (3.0, 8.0), . , (4.0, 9.0))