kml_sparse_?csrmultd
矩阵与矩阵计算,其中2个稀疏矩阵采用CSR格式存储,为基1索引,具体执行操作为:C := op(A) * B。
其中,C为稠密矩阵,A和B是采用CSR格式存储的稀疏矩阵。
op(A)根据参数是以下3种情况之一:
- op(A) = A
- op(A) = AT
- op(A) = AH
接口定义
C interface:
kml_sparse_status_t kml_sparse_scsrmultd(const kml_sparse_operation_t opt, const KML_INT m, const KML_INT n, const KML_INT k, const float *a, const KML_INT *ja, const KML_INT *ia, const float *b, const KML_INT *jb, const KML_INT *ib, float *c, const KML_INT ldc);
kml_sparse_status_t kml_sparse_dcsrmultd(const kml_sparse_operation_t opt, const KML_INT m, const KML_INT n, const KML_INT k, const double *a, const KML_INT *ja, const KML_INT *ia, const double *b, const KML_INT *jb, const KML_INT *ib, double *c, const KML_INT ldc);
kml_sparse_status_t kml_sparse_ccsrmultd(const kml_sparse_operation_t opt, const KML_INT m, const KML_INT n, const KML_INT k, const KML_Complex8 *a, const KML_INT *ja, const KML_INT *ia, const KML_Complex8 *b, const KML_INT *jb, const KML_INT *ib, KML_Complex8 *c, const KML_INT ldc);
kml_sparse_status_t kml_sparse_zcsrmultd(const kml_sparse_operation_t opt, const KML_INT m, const KML_INT n, const KML_INT k, const KML_Complex16 *a, const KML_INT *ja, const KML_INT *ia, const KML_Complex16 *b, const KML_INT *jb, const KML_INT *ib, KML_Complex16 *c, const KML_INT ldc);
Fortran interface:
RES = KML_SPARSE_SCSRMULTD(OPT, M, N, K, A, JA, IA, B, JB, IB, C, LDC);
RES = KML_SPARSE_DCSRMULTD(OPT, M, N, K, A, JA, IA, B, JB, IB, C, LDC);
RES = KML_SPARSE_CCSRMULTD(OPT, M, N, K, A, JA, IA, B, JB, IB, C, LDC);
RES = KML_SPARSE_ZCSRMULTD(OPT, M, N, K, A, JA, IA, B, JB, IB, C, LDC);
参数
参数名 |
类型 |
描述 |
输入/输出 |
---|---|---|---|
opt |
枚举类型kml_sparse_operation_t |
表示是否转置:
|
输入 |
m |
整型数 |
矩阵A的行数,取值范围为[1, MAX_KML_INT]。 |
输入 |
n |
整型数 |
矩阵A的列数,取值范围为[1, MAX_KML_INT]。 |
输入 |
k |
整型数 |
矩阵B的列数,取值范围为[1, MAX_KML_INT]。 |
输入 |
a |
|
CSR格式中values数组,存储矩阵A的非零元素。 |
输入 |
ja |
整型数组 |
CSR格式中columns数组,用于表示矩阵A中非零元素所在的列索引。 |
输入 |
ia |
整型数组 |
长度为m+1的数组,包含矩阵A的行索引,ia[i] - ia[0]表示第i行第一个非零元素在val和indx数组内的下标。 |
输入 |
b |
|
CSR格式中values数组,存储矩阵B非零元素。 |
输入 |
jb |
整型数组 |
CSR格式中columns数组,用于表示矩阵B非零元素所在的列索引。 |
输入 |
ib |
整型数组 |
矩阵B行索引,ib[i] – ib[0]表示第i行第一个非零元素在val和indx数组内的下标。 |
输入 |
c |
|
矩阵C的数组。 |
输出 |
ldc |
整型数 |
稠密矩阵C的主维度,ldc*kMAX_KML_INT。 |
输入 |
返回值
函数执行状态,枚举类型kml_sparse_status_t。
依赖
C: "kspblas.h"
Fortran: "kspblas.f03"
示例
C interface:
kml_sparse_operation_t opt = KML_SPARSE_OPERATION_NON_TRANSPOSE; KML_INT m = 3; KML_INT n = 3; KML_INT k = 3; float a[4] = {1, 5, 4, 5}; KML_INT ja[4] = {3, 1, 1, 1}; KML_INT ia[4] = {1, 3, 4, 5}; float b[4] = {9, 4, 2, 8}; KML_INT jb[4] = {2, 3, 1, 1}; KML_INT ib[4] = {1, 3, 4, 5}; float c[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; KML_INT ldc = 3; kml_sparse_status_t status = kml_sparse_scsrmultd(opt, m, n, k, a, ja, ia, b, jb, ib, c, ldc); /* * Output c: * 8.00 0.00 0.00 45.00 36.00 45.00 20.00 16.00 20.00 * */
Fortran interface:
INTEGER(C_INT) :: OPT = KML_SPARSE_OPERATION_NON_TRANSPOSE INTEGER(C_INT) :: M = 3 INTEGER(C_INT) :: N = 3 INTEGER(C_INT) :: K = 3 REAL(C_FLOAT) :: A(4), B(4), C(9) INTEGER(C_INT) :: JA(4), IA(4), JB(4), IB(4) INTEGER(C_INT) :: LDC = 3 INTEGER(C_INT) :: STATUS DATA A/1, 5, 4, 5/ DATA B/9, 4, 2, 8/ DATA C/0, 0, 0, 0, 0, 0, 0, 0, 0/ DATA JA/3, 1, 1, 1/ DATA IA/1, 3, 4, 5/ DATA JB /2, 3, 1, 1/ DATA IB /1, 3, 4, 5/ STATUS = KML_SPARSE_SCSRMULTD(OPT, M, N, K, A, JA, IA, B, JB, IB, C, LDC) ! ! OUTPUT C: ! 8.00 0.00 0.00 45.00 36.00 45.00 20.00 16.00 20.00 !