kml_sparse_?csrgemv
Compute the product of a vector and a sparse matrix that is stored in the CSR format. The operation is defined as follows:
y = A * x, y = AT * x, or y = AH * x
x and y are vectors, and A is a sparse matrix in the CSR format (3-array variation) with one-based indexing.
Interface Definition
C interface:
kml_sparse_status_t kml_sparse_scsrgemv(const kml_sparse_operation_t opt, 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_dcsrgemv(const kml_sparse_operation_t opt, 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_ccsrgemv(const kml_sparse_operation_t opt, 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_zcsrgemv(const kml_sparse_operation_t opt, 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_SCSRGEMV(OPT, M, A, IA, JA, X, Y);
RES = KML_SPARSE_DCSRGEMV(OPT, M, A, IA, JA, X, Y);
RES = KML_SPARSE_CCSRGEMV(OPT, M, A, IA, JA, X, Y);
RES = KML_SPARSE_ZCSRGEMV(OPT, M, A, IA, JA, X, Y);
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
opt |
Enumeration type kml_sparse_operation_t |
Operation on matrix A.
|
Input |
m |
Integer |
Number of rows and columns in matrix A. The value range is [1, MAX_KML_INT]. |
Input |
a |
|
Array values for storing non-zero elements in matrix A |
Input |
ia |
Integer |
Vector whose length is m+1. ia[i]-1 indicates the index of the first non-zero element in the ith row of matrix A in the val array. |
Input |
ja |
Integer |
ja[i] indicates the column number of the ith element of the val array in matrix A. |
Input |
x |
|
Array of vector x |
Input |
y |
|
Array of vector y, which is output after being updated. |
Input/Output |
The function does not verify the integrity of parameters. Ensure that the elements in ia and ja do not exceed the maximum index value of the input matrix.
Return Value
Function execution status. The enumeration type is kml_sparse_status_t.
Dependencies
C: "kspblas.h"
Fortran: "kspblas.f03"
Examples
C interface:
kml_sparse_operation_t opt = KML_SPARSE_OPERATION_NON_TRANSPOSE;
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_scsrgemv(opt, m, a, ia, ja, x, y);
/*
* Output Y:
* 28.000000 -32.000000 41.000000 9.000000
*
*/
Fortran interface:
INTEGER(C_INT) :: OPT = KML_SPARSE_OPERATION_NON_TRANSPOSE
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_SCSRGEMV(OPT, M, A, IA, JA, X, Y)
!
! OUTPUT Y:
! 28.000000 -32.000000 41.000000 9.000000
!


