---
title: ?asum
description: "向量元素绝对值求和（对于复数，则实部和虚部分别取绝对值后再求和）。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/2200/accel/kunpengaccel_kml_16_0016.html
sourcePath: /source/zh/kunpengboostkithistory/2200/accel/kunpengaccel_kml_16_0016.html
indexId: d245f92574c78f7d7fbab63a64e0043f136741408cb15f3efe960b716c2b0ecf74
---
# ?asum

向量元素绝对值求和（对于复数，则实部和虚部分别取绝对值后再求和）。

#### 接口定义

C interface：

float cblas_sasum(const BLASINT n, const float *x, const BLASINT incx);

double cblas_dasum(const BLASINT n, const double *x, const BLASINT incx);

float cblas_scasum(const BLASINT n, const void *x, const BLASINT incx);

double cblas_dzasum(const BLASINT n, const void *x, const BLASINT incx);

Fortran interface：

RES = SASUM(N, X, INCX)

RES = DASUM(N, X, INCX)

RES = SCASUM(N, X, INCX)

RES = DZASUM(N, X, INCX)


#### 参数

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


#### 依赖

#include "kblas.h"


#### 示例

C interface：

```
int n = 5, incx = 1, incy = 1;
/*
*  Input X:  0.340188, -0.105617, 0.283099, 0.298440, 0.411647
*/
float x[5] = {0.340188, -0.105617, 0.283099, 0.298440, 0.411647};
float res = cblas_sasum(n, x, incx);
/*
*  Output : 1.438991
*/
```

Fortran interface：

```
INTEGER :: N=5
INTEGER :: INCX=1
REAL(4) X(5)
DATA X /0.340188, -0.105617, 0.283099, 0.298440, 0.411647/
RES=SASUM(N,X,INCX)
*     Output : 1.438991
```
