kml_sparse_?csradd
Compute the sum of two sparse matrices that are stored in the CSR format. C = A + beta * op(B)
A, B, and C are sparse matrices in the CSR format (3-array variation) with one-based indexing.
op(B) can be defined as:
- op(B) = B
- op(B) = BT
- op(B) = BH
Interface Definition
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);
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
opt |
Enumeration type kml_sparse_operation_t |
Indicates whether to transpose.
|
Input |
request |
Integer |
|
Input |
sort |
Integer |
|
Input |
m |
Integer |
Number of rows in matrix A. The value range is [1, MAX_KML_INT]. |
Input |
n |
Integer |
Number of columns in matrix A |
Input |
a |
|
Array containing non-zero elements of matrix A |
Input |
ja |
Integer array |
Array containing column indices in the CSR format |
Input |
ia |
Integer array |
Array of length m+1, containing row indices of matrix A. ia[i] - ia[0] indicates the subscript of the first non-zero element in row i in the val and indx arrays. |
Input |
beta |
|
Scalar beta |
Input |
b |
|
Array containing non-zero elements of matrix B |
Input |
jb |
Integer array |
Array containing column indices in the CSR format |
Input |
ib |
Integer array |
Array containing row indices of sparse matrix B in the CSR format (3-array variation). The array size is m+1 when the matrix is not transposed or n+1 when the matrix is transposed. ib[i] - ib[0] indicates the subscript of the first non-zero element in the ith row in the val and indx arrays. |
Input |
c |
|
Array containing non-zero elements of matrix C |
Input/Output |
jc |
Integer array |
Array containing column indices in the CSR format |
Input/Output |
ic |
Integer array |
Array of length m+1, containing row indices of matrix C. ic[i] - ic[0] indicates the subscript of the first non-zero element in the ith row in the val and indx arrays. |
Input/Output |
nzmax |
Integer |
Maximum number of non-zero elements in matrix C. The function stops computing when the number of non-zero elements exceeds the specified value of nzmax. This parameter is valid only when request is set to 0 or 2. |
Input |
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 = 3;
KML_INT n = 3;
KML_INT request = 0; // Compute the c, jc, and ic arrays at the same time.
KML_INT sort = 0; // The row indices for elements in a and b have been sorted before input.
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 ! Compute the C, JC, and IC arrays at the same time.
INTEGER(C_INT) :: SORT = 0 ! The row indices for elements in a and b have been sorted before input.
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
!