kml_sparse_?csrsymv
矩阵与向量计算,稀疏矩阵采用CSR格式存储,具体执行操作如下:
y = A * x
其中,x和y为向量,A是的上三角或者下三角的对称矩阵,采用CSR格式3数组存储。仅支持矩阵indx从1开始的矩阵。
接口定义
C interface:
kml_sparse_status_t kml_sparse_scsrsymv(const kml_sparse_fill_mode_t uplo, const KML_INT m, const float *a, const KML_INT *ia, const KML_INT *ja, const float *x, float *y);
kml_sparse_status_t kml_sparse_dcsrsymv(const kml_sparse_fill_mode_t uplo, const KML_INT m, const double *a, const KML_INT *ia, const KML_INT *ja, const double *x, double *y);
kml_sparse_status_t kml_sparse_ccsrsymv(const kml_sparse_fill_mode_t uplo, const KML_INT m, const KML_Complex8 *a, const KML_INT *ia, const KML_INT *ja, const KML_Complex8 *x, KML_Complex8 *y);
kml_sparse_status_t kml_sparse_zcsrsymv(const kml_sparse_fill_mode_t uplo, const KML_INT m, const KML_Complex16 *a, const KML_INT *ia, const KML_INT *ja, const KML_Complex16 *x, KML_Complex16 *y);
Fortran interface:
RES = KML_SPARSE_SCSRSYMV(UPLO, M, A, IA, JA, X, Y);
RES = KML_SPARSE_DCSRSYMV(UPLO, M, A, IA, JA, X, Y);
RES = KML_SPARSE_CCSRSYMV(UPLO, M, A, IA, JA, X, Y);
RES = KML_SPARSE_ZCSRSYMV(UPLO, M, A, IA, JA, X, Y);
参数
参数名 |
类型 |
描述 |
输入/输出 |
---|---|---|---|
uplo |
枚举类型kml_sparse_fill_mode_t uplo |
指示矩阵A的上三角或者下三角被使用:
|
输入 |
m |
整型数 |
表示A矩阵的行数和列数,取值范围为[1, MAX_KML_INT]。 |
输入 |
a |
|
A矩阵中的非零元素。 |
输入 |
ia |
整型数组 |
长度为m+1的向量。 ia[i]-1表示A矩阵第i行第一个非零元素在val数组中的索引。 |
输入 |
ja |
整型数组 |
ja[i]表示val数组中第i个元素在矩阵A中的列序号。 |
输入 |
x |
|
向量x。 |
输入 |
y |
|
向量y,更新后输出。 |
输入/输出 |
返回值
函数执行状态,枚举类型kml_sparse_status_t。
依赖
C: "kspblas.h"
Fortran: "kspblas.f03"
示例
C interface:
kml_sparse_fill_mode_t uplo = KML_SPARSE_FILL_MODE_LOWER; KML_INT m = 4; float a[9] = {2, -3, 7, 1, -6, 8, -4, 5, 9}; KML_INT ja[9] = {1, 2, 4, 3, 4, 1, 3, 4, 1}; KML_INT ia[5] = {1, 4, 6, 9, 10}; float x[4] = {1, 3, -2, 5}; float y[4] = {-1, 1, 5, 3}; kml_sparse_status_t status = kml_sparse_scsrsymv(uplo, m, a, ia, ja, x, y); /* * Output Y: * 31.000000 0.000000 16.000000 9.000000 * */
Fortran interface:
INTEGER(C_INT) :: UPLO = KML_SPARSE_FILL_MODE_LOWER INTEGER(C_INT) :: M = 4 REAL(C_FLOAT) :: A(9), X(4), Y(4) INTEGER(C_INT) :: JA(9), IA(5) INTEGER(C_INT) :: STATUS DATA A/2, -3, 7, 1, -6, 8, -4, 5, 9/ DATA JA/1, 2, 4, 3, 4, 1, 3, 4, 1/ DATA IA/1, 4, 6, 9, 10/ DATA X/1, 3, -2, 5/ DATA Y/-1, 1, 5, 3/ STATUS = KML_SPARSE_SCSRSYMV(UPLO, M, A, IA, JA, X, Y) ! ! OUTPUT Y: ! 31.000000 0.000000 16.000000 9.000000 ! !