kml_sparse_?cscmm
Compute the product of matrices. One of them is a sparse matrix in the CSC format. The operation is defined as follows:
- C = alpha * A*B + beta * C
- C = alpha * AT * B + beta * C
- C = alpha * AH * B + beta * C
B and C are dense matrices, and A is a sparse matrix (m x k) stored in the CSC format.
Table 1 describes the relationship between layout and sparse matrix indexing.
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 |
Interface Definition
C interface:
kml_sparse_status_t kml_sparse_scscmm(const kml_sparse_operation_t opt, const KML_INT m, const KML_INT n, const KML_INT k, const float alpha, const char *matdescra, const float *val, const KML_INT *indx, const KML_INT *pntrb, const KML_INT *pntre, const float *b, const KML_INT ldb, const float beta , float *c , const KML_INT ldc);
kml_sparse_status_t kml_sparse_dcscmm(const kml_sparse_operation_t opt, const KML_INT m, const KML_INT n, const KML_INT k, const double alpha, const char *matdescra, const double *val, const KML_INT *indx, const KML_INT *pntrb, const KML_INT *pntre, const double *b, const KML_INT ldb, const double beta , double *c , const KML_INT ldc);
kml_sparse_status_t kml_sparse_ccscmm(const kml_sparse_operation_t opt, const KML_INT m, const KML_INT n, const KML_INT k, 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 *b, const KML_INT ldb, const KML_Complex8 beta , KML_Complex8 *c , const KML_INT ldc);
kml_sparse_status_t kml_sparse_zcscmm(const kml_sparse_operation_t opt, const KML_INT m, const KML_INT n, const KML_INT k, 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 *b, const KML_INT ldb, const KML_Complex16 beta , KML_Complex16 *c , const KML_INT ldc);
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
opt |
Enumeration type kml_sparse_operation_t |
Indicates whether to transpose.
|
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 C. The value range is [1, MAX_KML_INT]. |
Input |
k |
Integer |
Number of columns in matrix A. The value range is [1, MAX_KML_INT]. |
Input |
alpha |
|
Scalar alpha |
Input |
matdescra |
Char pointer |
Matrix operation attribute. For details, see the description of matdescra. |
Input |
val |
|
Array values storing non-zero elements of matrix A in the CSC format. The length is pntre[m-1] - pntrb[0]. |
Input |
indx |
Integer array |
Array columns in the CSC format, which contains the row indices for non-zero elements in matrix A |
Input |
pntrb |
Integer array |
Array of length m, containing column indices of matrix A. pntrb[i] - pntrb[0] indicates the subscript of the first non-zero element in column i in the val and indx arrays. |
Input |
pntre |
Integer array |
Array of length m, containing column indices of matrix A. pntre[i] - pntrb[0]-1 indicates the subscript of the last non-zero element in column i in the val and indx arrays. |
Input |
b |
|
Array value of matrix B |
Input |
ldb |
Integer array |
|
Input |
beta |
|
Scalar beta |
Input |
c |
|
Array value of matrix C |
Input/Output |
ldc |
Integer array |
|
Input |
Table 2 describes the parameter constraints on matrix B.
opt |
Matrix Scale |
Data Layout |
Value Range |
|---|---|---|---|
op(A) = A |
k * n |
Row-major order |
k * ldb |
op(A) = A |
k * n |
Column-major order |
ldb * n |
op(A) = AT or AH |
m x n |
Row-major order |
m * ldb |
op(A) = AT or AH |
m x n |
Column-major order |
ldb * n |
Table 3 describes the parameter constraints on matrix C.
opt |
Matrix Scale |
Data Layout |
Value Range |
|---|---|---|---|
op(A) = A |
m x n |
Row-major order |
m * ldc |
op(A) = A |
m x n |
Column-major order |
ldc * n |
op(A) = AT or AH |
k * n |
Row-major order |
k * ldc |
op(A) = AT or AH |
k * n |
Column-major order |
ldc * n |
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 k = 3;
float alpha = 1.0;
float beta = 1.0;
char *matdescra = "G00C"; // General matrix with zero-based indexing
float val[4] = {8, 5, 2, 9};
KML_INT indx[4] = {0, 1, 2, 0};
KML_INT pntrb[3] = {0, 0, 1};
KML_INT pntre[3] = {0, 1, 4};
float b[9] = {1, 5, 7, 4, 7, 7, 3, 3, 7};
float c[9] = {0, 8, 8, 0, 2, 8, 3, 5, 6};
KML_INT ldb = 3;
KML_INT ldc = 3;
kml_sparse_status_t status = kml_sparse_scscmm(opt, m, n, k, alpha, matdescra, val, indx, pntrb, pntre, b, ldb, beta, c, ldc);
/*
* Output c:
* 59.00 91.00 127.00
15.00 17.00 43.00
9.00 11.00 20.00
*
* */
