kml_sparse_?cscmm
矩阵与矩阵计算,其中一个稀疏矩阵采用CSC格式存储。具体执行操作如下:
- C = alpha * A*B + beta * C
- C = alpha * AT * B + beta * C
- C = alpha * AH * B + beta * C
其中,B和C为稠密矩阵,A是采用CSC格式存储的mxk的稀疏矩阵。
layout与sparse matrix indexing的关系如表1所示。
Sparse matrix indexing |
Dense matrix layout |
---|---|
KML_SPARSE_INDEX_BASE_ZERO |
KML_SPARSE_LAYOUT_ROW_MAJOR |
KML_SPARSE_INDEX_BASE_ONE |
KML_SPARSE_LAYOUT_COLUMN_MAJOR |
接口定义
C interface:
kml_sparse_status_t kml_sparse_scscmm(const kml_sparse_operation_t opt, const KML_INT m, const KML_INT n, const KML_INT k, const float alpha, const char *matdescra, const float *val, const KML_INT *indx, const KML_INT *pntrb, const KML_INT *pntre, const float *b, const KML_INT ldb, const float beta , float *c , const KML_INT ldc);
kml_sparse_status_t kml_sparse_dcscmm(const kml_sparse_operation_t opt, const KML_INT m, const KML_INT n, const KML_INT k, const double alpha, const char *matdescra, const double *val, const KML_INT *indx, const KML_INT *pntrb, const KML_INT *pntre, const double *b, const KML_INT ldb, const double beta , double *c , const KML_INT ldc);
kml_sparse_status_t kml_sparse_ccscmm(const kml_sparse_operation_t opt, const KML_INT m, const KML_INT n, const KML_INT k, const KML_Complex8 alpha, const char *matdescra, const KML_Complex8 *val, const KML_INT *indx, const KML_INT *pntrb, const KML_INT *pntre, const KML_Complex8 *b, const KML_INT ldb, const KML_Complex8 beta , KML_Complex8 *c , const KML_INT ldc);
kml_sparse_status_t kml_sparse_zcscmm(const kml_sparse_operation_t opt, const KML_INT m, const KML_INT n, const KML_INT k, const KML_Complex16 alpha, const char *matdescra, const KML_Complex16 *val, const KML_INT *indx, const KML_INT *pntrb, const KML_INT *pntre, const KML_Complex16 *b, const KML_INT ldb, const KML_Complex16 beta , KML_Complex16 *c , const KML_INT ldc);
参数
参数名 |
类型 |
描述 |
输入/输出 |
---|---|---|---|
opt |
枚举类型kml_sparse_operation_t |
表示是否转置:
|
输入 |
m |
整型数 |
矩阵A的行数,取值范围为[1, MAX_KML_INT]。 |
输入 |
n |
整型数 |
矩阵C的列数,取值范围为[1, MAX_KML_INT]。 |
输入 |
k |
整型数 |
矩阵A的列数,取值范围为[1, MAX_KML_INT]。 |
输入 |
alpha |
|
标量alpha。 |
输入 |
matdescra |
char指针 |
矩阵的操作属性,具体参考matdescra说明。 |
输入 |
val |
|
CSC格式中values数组,存储矩阵A的非零元素,长度为pntre[m-1] - pntrb[0]。 |
输入 |
indx |
整型数组 |
CSC格式中columns数组,用于表示矩阵A中非零元素所在的行索引。 |
输入 |
pntrb |
整型数组 |
长度为m的数组,包含矩阵A的列索引,pntrb[i] - pntrb[0]表示第i列第一个非零元素在val和indx数组内的下标。 |
输入 |
pntre |
整型数组 |
长度为m的数组,包含矩阵A的列索引,pntre[i] - pntrb[0]-1表示第i列最后一个非零元素在val和indx数组内的下标。 |
输入 |
b |
|
矩阵B的value数组。 |
输入 |
ldb |
整型数组 |
|
输入 |
beta |
|
标量beta。 |
输入 |
c |
|
矩阵C的value数组。 |
输入/输出 |
ldc |
整型数组 |
|
输入 |
B矩阵参数约束如表2所示。
opt |
B矩阵规模 |
B矩阵数据排布 |
参数范围 |
---|---|---|---|
op(A) = A |
k * n |
行主序 |
k * ldbMAX_KML_INT |
op(A) = A |
k * n |
列主序 |
ldb * n MAX_KML_INT |
op(A) = AT或AH |
m * n |
行主序 |
m * ldbMAX_KML_INT |
op(A) = AT或AH |
m * n |
列主序 |
ldb * n MAX_KML_INT |
C矩阵参数约束如表3所示。
opt |
C矩阵规模 |
C矩阵数据排布 |
参数范围 |
---|---|---|---|
op(A) = A |
m * n |
行主序 |
m * ldcMAX_KML_INT |
op(A) = A |
m * n |
列主序 |
ldc * n MAX_KML_INT |
op(A) = AT或AH |
k * n |
行主序 |
k * ldc MAX_KML_INT |
op(A) = AT或AH |
k * n |
列主序 |
ldc * n MAX_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 alpha = 1.0; float beta = 1.0; char *matdescra = "G00C"; //一般矩阵,基0索引 float val[4] = {8, 5, 2, 9}; KML_INT indx[4] = {0, 1, 2, 0}; KML_INT pntrb[3] = {0, 0, 1}; KML_INT pntre[3] = {0, 1, 4}; float b[9] = {1, 5, 7, 4, 7, 7, 3, 3, 7}; float c[9] = {0, 8, 8, 0, 2, 8, 3, 5, 6}; KML_INT ldb = 3; KML_INT ldc = 3; kml_sparse_status_t status = kml_sparse_scscmm(opt, m, n, k, alpha, matdescra, val, indx, pntrb, pntre, b, ldb, beta, c, ldc); /* * Output c: * 59.00 91.00 127.00 15.00 17.00 43.00 9.00 11.00 20.00 * * */