---
title: ?dot
description: "计算向量与向量的点积。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/240RC2/accel/kunpengaccel_kml_16_0019.html
sourcePath: /source/zh/kunpengboostkithistory/240RC2/accel/kunpengaccel_kml_16_0019.html
indexId: 41b8152ee35cb140c1af76f961818d31653d860f22bf60a3f616d1950633098376
---
# ?dot

计算向量与向量的点积。

即。x和y是含有n个元素的向量。

#### 接口定义

C interface：

float cblas_sdot(const BLASINT n, const float *x, const BLASINT incx, const float *y, const BLASINT incy);

double cblas_ddot(const BLASINT n, const double *x, const BLASINT incx, const double *y, const BLASINT incy);

Fortran interface：

RES = SDOT(N, X, INCX, Y, INCY)

RES = DDOT(N, X, INCX, Y, INCY)


#### 参数

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


#### 返回值

向量点积结果。

- sdot是单精度浮点类型。
- ddot是双精度浮点类型。


#### 依赖

#include "kblas.h"


#### 示例

C interface：

```
float res;
int n = 5, incx = 1, incy = 1;
/**
*   X: 0.340188, -0.105617, 0.283099, 0.298440, 0.411647
*   Y: -0.302449, -0.164777, 0.268230, -0.222225, 0.053970
*/
float x[5] = {0.340188, -0.105617, 0.283099, 0.298440, 0.411647};
float y[5] = {-0.302449, -0.164777, 0.268230, -0.222225, 0.053970};
res = cblas_sdot(n, x, incx, y, incy);
/**
*   Output:
*     -0.053655
*/
```

Fortran interface：

```
REAL(4) :: RES
INTEGER :: N=5
INTEGER :: INCX=1
INTEGER :: INCY=1
REAL(4) :: X(5)
DATA X /0.340188, -0.105617, 0.283099, 0.298440, 0.411647/
REAL(4) :: Y(5)
DATA Y /-0.302449, -0.164777, 0.268230, -0.222225, 0.053970/
RES=SDOT(N, X, INCX, Y, INCY)
*     Output :  -0.053655
```
