kml_sparse_?dotci_sub
共轭点积(希尔伯特空间)。
x · y = xˆH * y,即x向量中的元素取其共轭复数后与y向量中对应元素相乘然后累加(复数a + bi的共轭为a - bi),计算公式表示为:conjg(x[0]) * y[indx[0]] + ... + conjg(x[nz-1]) * y[indx[nz-1]]。
接口定义
C interface:
kml_sparse_status_t kml_sparse_cdotci_sub(const KML_INT nz, const KML_Complex8 *x, const KML_INT *indx, const KML_Complex8 *y, KML_Complex8 *dotci);
kml_sparse_status_t kml_sparse_zdotci_sub(const KML_INT nz, const KML_Complex16 *x, const KML_INT *indx, const KML_Complex16 *y, KML_Complex16 *dotci);
Fortran interface:
RES = KML_SPARSE_CDOTCI_SUB(NZ, X, INDX, Y, DOTCI);
RES = KML_SPARSE_ZDOTCI_SUB(NZ, X, INDX, Y, DOTCI);
参数
参数名 |
类型 |
描述 |
输入/输出 |
---|---|---|---|
nz |
整型数 |
x及indx数组中元素的个数。 |
输入 |
x |
|
存储非零元素的数组x,大于或等于nz。 |
输入 |
indx |
整型数组 |
indx[i]表示x数组中第i个元素在稠密向量中的序列号,数组大于或等于nz。 |
输入 |
y |
|
数组y,大于或等于max(indx[i])。 |
输入 |
dotci |
|
返回共轭x与y的点积。 |
输入/输出 |
返回值
函数执行状态,枚举类型kml_sparse_status_t。
依赖
C: "kspblas.h"
Fortran: "kspblas.f03"
示例
C interface:
KML_INT nz = 2; KML_Complex8 dotci = {0, 0}; KML_INT indx[2] = {1, 2}; KML_Complex8 x[2] = {{1, 2}, {3, 4}}; KML_Complex8 y[4] = {{-1, 1}, {5, 3}, {-2, -3}, {4, 1}}; kml_sparse_status_t status = kml_sparse_cdotci_sub(nz, x, indx, y, &dotci); /* * Output dotci: * {-7.000000, -8.000000} */
Fortran interface:
INTEGER(C_INT) :: NZ = 2 INTEGER(C_INT) :: STATUS INTEGER(C_INT) :: I TYPE(KML_COMPLEX8), TARGET :: DOTCI = KML_COMPLEX8(0, 0) INTEGER(C_INT) :: INDX(2) TYPE(KML_COMPLEX8) :: CX(2), Y(4) REAL(C_FLOAT) :: X(4), Y(8) TYPE(C_PTR) :: PDOTCI PDOTCI = C_LOC(DOTCI) DATA INDX/1, 2/ DATA X/1, 2, 3, 4/ DATA Y /-1, 1, 5, 3, -2, -3, 4, 1/ I = 1 DO WHILE(I <= 2) CX(I)%REAL = X(2 * I - 1) CX(I)%IMAG = X(2 * I) END DO I = 1 DO WHILE(I <= 4) CY(I)%REAL = Y(2 * I - 1) CY(I)%IMAG = Y(2 * I) END DO STATUS = KML_SPARSE_CDOTCI_SUB(NZ, CX, INDX, CY, PDOTCI) ! ! OUTPUT DOTCI: ! {-7.000000, -8.000000} !