---
title: kml_sparse_?roti
description: "对2个实数类型的向量进行旋转操作。"
url: https://www.hikunpeng.com/document/detail/zh/kunpenghpcs/hpckit/devg/kunpengaccel_kml_0027.html
sourcePath: /source/zh/kunpenghpcs/hpckit/devg/kunpengaccel_kml_0027.html
indexId: 2a18ac29fd7e03604c373fc109d331c3c3851343ed88c7825831ddd4c2fb5faa61
---
# 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中，s是单精度浮点类型标量。 在droti中，s是双精度浮点类型标量。 | 标量。 | 输入 |


#### 返回值

函数执行状态，枚举类型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
!
```
