---
title: ?asum
description: "向量元素绝对值求和（对于复数，则实部和虚部分别取绝对值后再求和）。"
url: https://www.hikunpeng.com/document/detail/zh/kunpenghpcs/hpckit/devg/kunpengaccel_kml_0602.html
sourcePath: /source/zh/kunpenghpcs/hpckit/devg/kunpengaccel_kml_0602.html
indexId: 3b5b6c1228b21db9b525cfc083e5b3751c62bfb458f39529ed803e0b21aa213161
---
# ?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中是双精度浮点类型。 在sasum中是单精度浮点类型。 在scasum中是单精度复数类型。 在zasum中是双精度复数类型。 | 向量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
```
