kml_sparse_?csrsm
求解三角矩阵方程组计算,其中一个稀疏矩阵采用CSR格式存储,具体执行操作如下:
- A * y = alpha * x
- AT * y = alpha * x
- AH * y = alpha * x
其中,x和y为mxn的稠密矩阵,A是采用CSR格式存储的mxm的稀疏矩阵。矩阵A中的给定行的非零元素的存储顺序必须与行中显示的顺序相同(从左到右)。
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_scsrsm(const kml_sparse_operation_t opt, const KML_INT m, const KML_INT n, const float alpha, const char *matdescra, const float *val, const KML_INT *indx, const KML_INT *pntrb, const KML_INT *pntre, const float *x, const KML_INT ldx, float *y , const KML_INT ldy);
kml_sparse_status_t kml_sparse_dcsrsm(const kml_sparse_operation_t opt, const KML_INT m, const KML_INT n, const double alpha, const char *matdescra, const double *val, const KML_INT *indx, const KML_INT *pntrb, const KML_INT *pntre,const double *x, const KML_INT ldx, double *y , const KML_INT ldy);
kml_sparse_status_t kml_sparse_ccsrsm(const kml_sparse_operation_t opt, const KML_INT m, const KML_INT n, 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 *x, const KML_INT ldx, KML_Complex8 *y, const KML_INT ldy);
kml_sparse_status_t kml_sparse_zcsrsm(const kml_sparse_operation_t opt, const KML_INT m, const KML_INT n, 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 *x, const KML_INT ldx, KML_Complex16 *y , const KML_INT ldy);
参数
参数名 |
类型 |
描述 |
输入/输出 |
---|---|---|---|
opt |
枚举类型kml_sparse_operation_t |
表示是否转置:
|
输入 |
m |
整型数 |
矩阵A的行数,取值范围为[1, MAX_KML_INT]。 |
输入 |
n |
整型数 |
矩阵x的列数,取值范围为[1, MAX_KML_INT]。 |
输入 |
alpha |
|
标量alpha。 |
输入 |
matdescra |
char指针 |
矩阵的操作属性,具体参考matdescra说明。 |
输入 |
val |
|
CSR格式中values数组,存储矩阵A的非零元素,长度为pntre[m-1] - pntrb[0]。 |
输入 |
indx |
整型数组 |
CSR格式中columns数组,用于表示矩阵A中非零元素所在的列索引。 |
输入 |
pntrb |
整型数组 |
长度为m的数组,包含矩阵A的行索引,pntrb[i] - pntrb[0]表示第i行第一个非零元素在val和indx数组内的下标。 |
输入 |
pntre |
整型数组 |
长度为m的数组,包含矩阵A的行索引,pntre[i] - pntrb[0]-1表示第i行最后一个非零元素在val和indx数组内的下标。 |
输入 |
x |
|
矩阵x的value数组。 |
输入 |
ldx |
整型数组 |
|
输入 |
y |
|
矩阵y的value数组。 |
输入/输出 |
ldy |
整型数组 |
|
输入 |
x矩阵参数约束如表2所示。
opt |
x矩阵规模 |
x矩阵数据排布 |
参数范围 |
---|---|---|---|
op(A) = A或AT或AH |
m * n |
行主序 |
m * ldbMAX_KML_INT |
op(A) = A或AT或AH |
m * n |
列主序 |
ldb * nMAX_KML_INT |
y矩阵参数约束如表3所示。
opt |
y矩阵规模 |
y矩阵数据排布 |
参数范围 |
---|---|---|---|
op(A) = A或AT或AH |
m * n |
行主序 |
m * ldcMAX_KML_INT |
op(A) = A或AT或AH |
m * n |
列主序 |
ldc * nMAX_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 = 4; KML_INT n = 2; float alpha = 1.0; char *matdescra = "TLNF"; //三角矩阵,基1索引 float val[9] = {2, -3, 7, 1, -6, 8, -4, 5, 9}; KML_INT indx[9] = {1, 2, 4, 2, 4, 1, 3, 1, 4}; KML_INT pntrb[4] = {1, 4, 6, 8}; KML_INT pntre[4] = {4, 6, 8, 10}; float x[8] = {1, 3, -2, 5, 7, -3, 6, 8}; float y[8] = {0, 0, 0, 0, 0, 0, 0, 0}; KML_INT ldx = 4; KML_INT ldy = 4; kml_sparse_status_t status = kml_sparse_scsrsm(opt, m, n, alpha, matdescra, val, indx, pntrb, pntre, x, ldx, y, ldy); /* * Output Y: * 0.500000 3.000000 1.500000 0.277778 3.500000 -3.000000 5.500000 -1.055556 * * */