dswap: Swap two double-precision vectors.

View source: R/bigalgebra.R

dswapR Documentation

Swap two double-precision vectors.

Description

Exchange the elements of two double precision vectors in place. For I = 0 to N-1, swap DX(LX + I * INCX) with DY(LY + I * INCY) where LX and LY depend on the increment signs. When an optimized BLAS is available the implementation dispatches to DSWAP; otherwise a portable C loop performs the exchange.

Usage

dswap(N = NULL, X, INCX = 1L, Y, INCY = 1L)

Arguments

N

Number of elements in the input vectors. Defaults to the full length of X if NULL.

X

Double precision vector or matrix providing the first data block.

INCX

Storage spacing between elements of X.

Y

Double precision vector or matrix providing the second data block.

INCY

Storage spacing between elements of Y.

Details

When an optimized BLAS is available the implementation delegates to the Fortran DSWAP routine. Otherwise a portable C fallback performs the exchange directly while respecting the supplied vector increments.

Value

Invisibly returns NULL; both X and Y are modified in place.

See Also

[dcopy()], [daxpy()] and [dscal()].

Examples

set.seed(4670)
X <- matrix(runif(6), 3, 2)
Y <- matrix(runif(6), 3, 2)
X_original <- X
Y_original <- Y
dswap(X = X, Y = Y)
all.equal(X, Y_original)
all.equal(Y, X_original)

bigalgebra documentation built on Sept. 9, 2026, 5:12 p.m.