---
title: ?swap
description: "两个向量元素交换。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/240RC1/accel/kunpengaccel_kml_16_0030.html
sourcePath: /source/zh/kunpengboostkithistory/240RC1/accel/kunpengaccel_kml_16_0030.html
indexId: be79f0c303f8d258390223fd6009df23e95e11df40ebaa49f2a35dce730e0c4776
---
# ?swap

两个向量元素交换。

#### 接口定义

C interface：

void cblas_sswap(const BLASINT n, float *x, const BLASINT incx, float *y, const BLASINT incy);

void cblas_dswap(const BLASINT n, double *x, const BLASINT incx, double *y, const BLASINT incy);

void cblas_cswap(const BLASINT n, void *x, const BLASINT incx, void *y, const BLASINT incy);

void cblas_zswap(const BLASINT n, void *x, const BLASINT incx, void *y, const BLASINT incy);

Fortran interface：

CALL SSWAP(N, SX, INCX, SY, INCY)

CALL DSWAP(N, SX, INCX, SY, INCY)

CALL CSWAP(N, SX, INCX, SY, INCY)

CALL ZSWAP(N, SX, INCX, SY, INCY)


#### 参数

| 参数名 | 类型 | 描述 | 输入/输出 |
| --- | --- | --- | --- |
| n | 整型数 | 表示x、y向量的元素个数。 | 输入 |
| x | 在sswap中是双精度浮点类型。 在dswap中是单精度浮点类型。 在cswap中是单精度复数类型。 在zswap中是双精度复数类型。 | 向量x，向量规模至少是(1+(n\-1)\*abs(incx))。 | 输入/输出 |
| incx | 整型数 | 表示x向量增长步长。 | 输入 |
| y | 在sswap中是双精度浮点类型。 在dswap中是单精度浮点类型。 在cswap中是单精度复数类型。 在zswap中是双精度复数类型。 | 向量y，向量规模至少是(1+(n\-1)\*abs(incy))。 | 输入/输出 |
| incy | 整型数 | 表示y中向量元素增长步长。 | 输入 |


#### 依赖

#include "kblas.h"


#### 示例

C interface：

```
int n = 5, incx = 1, incy = 1;
/*
*  Input X:  0.340188, -0.105617, 0.283099, 0.298440, 0.411647
*  Input Y:  -0.302449, -0.164777, 0.268230, -0.222225, 0.053970
* */
float x[5] = {0.340188, -0.105617, 0.283099, 0.298440, 0.411647};
float y[5] = {-0.302449, -0.164777, 0.268230, -0.222225, 0.053970};
cblas_sswap(n, x, incx, y, incy);
/*
*  Output X: -0.302449, -0.164777, 0.268230, -0.222225, 0.053970
*  Output Y: 0.340188, -0.105617, 0.283099, 0.298440, 0.411647
* */
```

Fortran interface：

```
INTEGER :: N=5
INTEGER :: INCX=1
INTEGER :: INCY=1
REAL(4) :: X(5)
DATA X /0.340188, -0.105617, 0.283099, 0.298440, 0.411647/
REAL(4) :: Y(5)
DATA Y /-0.302449, -0.164777, 0.268230, -0.222225, 0.053970/
EXTERNAL SSWAP
CALL SSWAP(N, X, INCX, Y, INCY)
*     Output X: -0.302449, -0.164777, 0.268230, -0.222225, 0.053970
*     Output Y: 0.340188, -0.105617, 0.283099, 0.298440, 0.411647
```
