kml_sparse_?csradd
计算2个CSR格式的稀疏矩阵之和。C = A + beta * op(B)
A、B、C为3数组CSR格式稀疏矩阵,仅支持基1索引。
op(B)可能的操作为:
- op(B) = B
- op(B) = BT
- op(B) = BH
接口定义
C interface:
kml_sparse_status_t kml_sparse_scsradd(const kml_sparse_operation_t opt, const KML_INT request, const KML_INT sort, const KML_INT m, const KML_INT n, const float *a, const KML_INT *ja, KML_INT *ia, const float beta, const float *b, const KML_INT *jb, const KML_INT *ib, float *c, KML_INT *jc, KML_INT *ic, const KML_INT nzmax);
kml_sparse_status_t kml_sparse_dcsradd(const kml_sparse_operation_t opt, const KML_INT request, const KML_INT sort, const KML_INT m, const KML_INT n, const double *a, const KML_INT *ja, const KML_INT *ia, const double beta, const double *b, const KML_INT *jb, const KML_INT *ib, double *c, KML_INT *jc, KML_INT *ic, const KML_INT nzmax);
kml_sparse_status_t kml_sparse_ccsradd(const kml_sparse_operation_t opt, const KML_INT request, const KML_INT sort, const KML_INT m, const KML_INT n, const KML_Complex8 *a, const KML_INT *ja, const KML_INT *ia, const KML_Complex8 beta, const KML_Complex8 *b, const KML_INT *jb, const KML_INT *ib, KML_Complex8 *c, KML_INT *jc, KML_INT *ic, const KML_INT nzmax);
kml_sparse_status_t kml_sparse_zcsradd(const kml_sparse_operation_t opt, const KML_INT request, const KML_INT sort, const KML_INT m, const KML_INT n, const KML_Complex16 *a, const KML_INT *ja, const KML_INT *ia, const KML_Complex16 beta, const KML_Complex16 *b, const KML_INT *jb, const KML_INT *ib, KML_Complex16 *c, KML_INT *jc, KML_INT *ic, const KML_INT nzmax);
Fortran interface:
RES = KML_SPARSE_SCSRADD(OPT, REQUEST, SORT, M, N, A, JA, IA, BETA, B, JB, IB, C, JC, IC, NZMAX);
RES = KML_SPARSE_DCSRADD(OPT, REQUEST, SORT, M, N, A, JA, IA, BETA, B, JB, IB, C, JC, IC, NZMAX);
RES = KML_SPARSE_CCSRADD(OPT, REQUEST, SORT, M, N, A, JA, IA, BETA, B, JB, IB, C, JC, IC, NZMAX);
RES = KML_SPARSE_ZCSRADD(OPT, REQUEST, SORT, M, N, A, JA, IA, BETA, B, JB, IB, C, JC, IC, NZMAX);
参数
参数名 |
类型 |
描述 |
输入/输出 |
---|---|---|---|
opt |
枚举类型kml_sparse_operation_t |
表示是否转置:
|
输入 |
request |
整型数 |
|
输入 |
sort |
整型数 |
|
输入 |
m |
整型数 |
矩阵A的行数,取值范围为[1, MAX_KML_INT]。 |
输入 |
n |
整型数 |
矩阵A的列数。 |
输入 |
a |
|
矩阵A的非零元素数组。 |
输入 |
ja |
整型数组 |
CSR格式的列索引数组。 |
输入 |
ia |
整型数组 |
长度为m+1的数组,包含矩阵A的行索引,ia[i] - ia[0]表示第i行第一个非零元素在val和indx数组内的下标。 |
输入 |
beta |
|
标量beta。 |
输入 |
b |
|
矩阵B的非零元素数组。 |
输入 |
jb |
整型数组 |
CSR格式的列索引数组。 |
输入 |
ib |
整型数组 |
CSR格式稀疏矩阵B的三数组形式的行索引数组,非转置时大小为m+1,转置时大小为n+1,ib[i] - ib[0]表示第i行第一个非零元素在val和indx数组内的下标。 |
输入 |
c |
|
矩阵C的非零元素数组。 |
输入/输出 |
jc |
整型数组 |
CSR格式的列索引数组。 |
输入/输出 |
ic |
整型数组 |
长度为m+1的数组,包含矩阵C的行索引,ic[i] - ic[0]表示第i行第一个非零元素在val和indx数组内的下标。 |
输入/输出 |
nzmax |
整型数 |
矩阵C内的非零元素最大个数,当超过nzmax时,计算过程停止。该参数只有request=0或2时有效。 |
输入 |
函数内部不对参数做完整校验,接口调用者需保证ia和ja内部元素不超出矩阵最大索引值。
返回值
函数执行状态,枚举类型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 request = 0; //同时计算c,jc,ic三个数组 KML_INT sort = 0; //a,b每行元素的列索引输入前已排序 float beta = 1.0; float a[4] = {9, 4, 2, 2}; KML_INT ja[4] = {1, 3, 2, 2}; KML_INT ia[4] = {1, 3, 4, 5}; float b[4] = {2, 5, 9, 8}; KML_INT jb[4] = {2, 3, 2, 1}; KML_INT ib[4] = {1, 3, 4, 5}; float c[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; KML_INT jc[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; KML_INT ic[4] = {0, 0, 0, 0}; KML_INT nzmax = 9; kml_sparse_status_t status = kml_sparse_scsradd(opt, request, sort, m, n, a, ja, ia, beta, b, jb, ib, c, jc, ic, nzmax); /* * Output c: * 9.00 2.00 9.00 11.00 8.00 2.00 * Output jc: * 1 2 3 2 1 2 * Output ic: * 1 4 5 7 * */
Fortran interface:
INTEGER(C_INT) :: OPT = KML_SPARSE_OPERATION_NON_TRANSPOSE INTEGER(C_INT) :: M = 3 INTEGER(C_INT) :: N = 3 INTEGER(C_INT) :: REQUEST = 0 !同时计算C,JC,IC三个数组 INTEGER(C_INT) :: SORT = 0 !A,B每行元素的列索引输入前已排序 REAL(C_FLOAT) :: BETA = 1.0 REAL(C_FLOAT) :: A(4), B(4), C(6) INTEGER(C_INT) :: JA(4), IA(4), JB(4), IB(4), JC(6), IC(4) INTEGER(C_INT) :: NZMAX = 9 INTEGER(C_INT) :: STATUS DATA A/9, 4, 2, 2/ DATA B/2, 5, 9, 8/ DATA C/0, 0, 0, 0, 0, 0/ DATA JA/1, 3, 2, 2/ DATA IA/1, 3, 4, 5/ DATA JB/2, 3, 2, 1/ DATA IB/1, 3, 4, 5/ DATA JC/0, 0, 0, 0, 0, 0/ DATA IC/0, 0, 0, 0/ STATUS = KML_SPARSE_SCSRADD(OPT, REQUEST, SORT, M, N, A, JA, IA, BETA, B, JB, IB, C, JC, IC, NZMAX) ! ! OUTPUT C: ! 9.00 2.00 9.00 11.00 8.00 2.00 ! OUTPUT JC: ! 1 2 3 2 1 2 ! OUTPUT IC: ! 1 4 5 7 !