---
title: kml_sparse_?roti
description: "对2个实数类型的向量进行旋转操作。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/2200/accel/kunpengaccel_kml_16_0079.html
sourcePath: /source/zh/kunpengboostkithistory/2200/accel/kunpengaccel_kml_16_0079.html
indexId: b0368e6e837682586aaae48b3799e9367c9a19126a38416d0c798c675340483174
---
# kml_sparse_?roti

对2个实数类型的向量进行旋转操作。

x[i] = c*x[i] + s*y[indx[i]]

y[indx[i]] = c * y[indx[i]] - s * x[i]

#### 接口定义

C interface：

kml_sparse_status_t kml_sparse_sroti(const KML_INT nz, float *x, const KML_INT *indx, float *y, const float c, const float s);

kml_sparse_status_t kml_sparse_droti(const KML_INT nz, double *x, const KML_INT *indx, double *y, const double c, const double s);

Fortran interface：

RES = KML_SPARSE_SROTI(NZ, X, INDX, Y, C, S);

RES = KML_SPARSE_DROTI(NZ, X, INDX, Y, C, S);


#### 参数

| 参数名 | 类型 | 描述 | 输入/输出 |
| --- | --- | --- | --- |
| nz | 整型数 | x及indx数组中元素的个数。 | 输入 |
| x | 在sroti中，x是单精度浮点类型数组。 在droti中，x是双精度浮点类型数组。 | compressed格式的向量x，大于或等于nz。 | 输入/输出 |
| indx | 整型数组 | 存储要被加载到数组x中非零元素下标索引，大于或等于nz。 | 输入 |
| y | 在sroti中，y是单精度浮点类型数组。 在droti中，y是双精度浮点类型数组。 | full\-storage格式的向量y，大于或等于max(indx[i])。 | 输入/输出 |
| c | 在sroti中，c是单精度浮点类型数组。 在droti中，c是双精度浮点类型数组。 | 标量。 | 输入 |
| s | 在sroti中，z是单精度浮点类型数组。 在droti中，z是双精度浮点类型数组。 | 标量。 | 输入 |


#### 返回值

函数执行状态，枚举类型kml_sparse_status_t。


#### 依赖

C: "kspblas.h"

Fortran: "kspblas.f03"


#### 示例

C interface：

```
KML_INT nz = 2;
KML_INT indx[2] = {1, 2};
float x[2] = {1, 3};
float y[4] = {-1, 5, -2, 4};
float c = 1;
float s = 2;
kml_sparse_status_t status = kml_sparse_sroti(nz, x, indx, y, c, s);
/*
*  Output x:
*     11.000000    -1.000000
*  Output y:
*     -1.000000     3.000000    -8.000000     4.000000
*/
```

Fortran interface：

```
INTEGER(C_INT) :: NZ = 2
INTEGER(C_INT) :: INDX(2)
REAL(C_FLOAT) :: X(2), Y(4)
REAL(C_FLOAT) :: C = 1
REAL(C_FLOAT) :: S = 2
INTEGER(C_INT) :: STATUS
DATA INDX/1, 2/
DATA X/1, 3/
DATA Y/-1, 5, -2, 4/
STATUS = KML_SPARSE_SROTI(NZ, X, INDX, Y, C, S)
!
!  OUTPUT X:
!    11.000000    -1.000000
!  OUTPUT Y:
!     -1.000000     3.000000    -8.000000     4.000000
!
```
