---
title: ?laswp
description: "对矩阵做一系列的行交换操作。"
url: https://www.hikunpeng.com/document/detail/zh/kunpenghpcs/hpckit/devg/kunpengaccel_kml_0788.html
sourcePath: /source/zh/kunpenghpcs/hpckit/devg/kunpengaccel_kml_0788.html
indexId: a25219c037616ea5f54a6b2f3b427d0690f286890c66cc30a368821c46143a8661
---
# ?laswp

对矩阵做一系列的行交换操作。

#### 接口定义

C Interface：

void slaswp_(const int *n, float *a, const int *lda, const int *k1, const int *k2, const int *ipiv, const int *incx);

void dlaswp_(const int *n, double *a, const int *lda, const int *k1, const int *k2, const int *ipiv, const int *incx);

void claswp_(const int *n, float _Complex *a, const int *lda, const int *k1, const int *k2, const int *ipiv, const int *incx);

void zlaswp_(const int *n, double _Complex *a, const int *lda, const int *k1, const int *k2, const int *ipiv, const int *incx);

Fortran Interface：

SLASWP(N, A, LDA, K1, K2, IPIV, INCX);

DLASWP(N, A, LDA, K1, K2, IPIV, INCX);

CLASWP(N, A, LDA, K1, K2, IPIV, INCX);

ZLASWP(N, A, LDA, K1, K2, IPIV, INCX);


#### 参数

| 参数名 | 类型 | 描述 | 输入/输出 |
| --- | --- | --- | --- |
| N | 整数型 | 矩阵A的列数。 | 输入 |
| A | 在slaswp中为单精度浮点型。 在dlaswp中为双精度浮点型。 在claswp中为单精度复数型。 在zlaswp中为双精度复数型。 | 矩阵A，大小为LDA\*N。 调用前：原始矩阵A。 调用后：交换后的矩阵。 | 输入，输出 |
| LDA | 整数型 | 矩阵A的主维。 | 输入 |
| K1 | 整数型 | IPIV的索引值，用于表示交换的起始行。 | 输入 |
| K2 | 整数型 | IPIV的索引值，用于表示交换的末尾行，K2>=K1。 | 输入 |
| IPIV | 整数型数组 | 交换的索引数组，大小为K1+(K2\-K1)\*abs(INCX)。 | 输入 |
| INCX | 整数型 | IPIV的取值步长。 | 输入 |


#### 依赖

#include "klapack.h"


#### 示例

C Interface：

```
const int n = 4;
const int lda = n;
const int k1 = 1;
const int k2 = 2;
const int incx = 1;
double a[] = { 1.0, 1.0, 1.0, 1.0,
2.0, 2.0, 2.0, 2.0,
8.0, 3.0, 3.0, 3.0,
4.0, 4.0, 4.0, 4.0};
int ipiv[3] = {3,1};
dlaswp_(&n, a, &lda, &k1, &k2, ipiv, &incx);
/*
* Output:
* a output:
*
*  1.000000    1.000000    1.000000    1.000000
*  2.000000    2.000000    2.000000    2.000000
*  3.000000    3.000000    8.000000    3.000000
*  4.000000    4.000000    4.000000    4.000000
```

Fortran Interface：

```
PARAMETER (n = 4)
PARAMETER (lda = n)
PARAMETER (k1 = 1)
PARAMETER (k2 = 2)
PARAMETER (incx = 1)
REAL(8) :: a(lda, n)
INTEGER :: ipiv(3)
DATA a / 1.0, 1.0, 1.0, 1.0,
$        2.0, 2.0, 2.0, 2.0,
$        8.0, 3.0, 3.0, 3.0,
$        4.0, 4.0, 4.0, 4.0 /
DATA ipiv / 3, 1 /
EXTERNAL DLASWP
CALL DLASWP(n, a, lda, k1, k2, ipiv, incx);
*
* Output:
* a output (stored in column-major)
*  1.000000    1.000000    1.000000    1.000000
*  2.000000    2.000000    2.000000    2.000000
*  3.000000    3.000000    8.000000    3.000000
*  4.000000    4.000000    4.000000    4.000000
```
