我要评分
获取效率
正确性
完整性
易理解

kml_sparse_?csrmultd

Compute the product of matrices. Two of them are sparse matrices stored in the CSR format with one-based indexing.

C = op(A) * B

C is a dense matrix, and A and B are sparse matrices in the CSR format.

op(A) can be defined as:

  • op(A) = A
  • op(A) = AT
  • op(A) = AH

Interface Definition

C interface:

kml_sparse_status_t kml_sparse_scsrmultd(const kml_sparse_operation_t opt, const KML_INT m, const KML_INT n, const KML_INT k, const float *a, const KML_INT *ja, const KML_INT *ia, const float *b, const KML_INT *jb, const KML_INT *ib, float *c, const KML_INT ldc);

kml_sparse_status_t kml_sparse_dcsrmultd(const kml_sparse_operation_t opt, const KML_INT m, const KML_INT n, const KML_INT k, const double *a, const KML_INT *ja, const KML_INT *ia, const double *b, const KML_INT *jb, const KML_INT *ib, double *c, const KML_INT ldc);

kml_sparse_status_t kml_sparse_ccsrmultd(const kml_sparse_operation_t opt, const KML_INT m, const KML_INT n, const KML_INT k, const KML_Complex8 *a, const KML_INT *ja, const KML_INT *ia, const KML_Complex8 *b, const KML_INT *jb, const KML_INT *ib, KML_Complex8 *c, const KML_INT ldc);

kml_sparse_status_t kml_sparse_zcsrmultd(const kml_sparse_operation_t opt, const KML_INT m, const KML_INT n, const KML_INT k, const KML_Complex16 *a, const KML_INT *ja, const KML_INT *ia, const KML_Complex16 *b, const KML_INT *jb, const KML_INT *ib, KML_Complex16 *c, const KML_INT ldc);

Fortran interface:

RES = KML_SPARSE_SCSRMULTD(OPT, M, N, K, A, JA, IA, B, JB, IB, C, LDC);

RES = KML_SPARSE_DCSRMULTD(OPT, M, N, K, A, JA, IA, B, JB, IB, C, LDC);

RES = KML_SPARSE_CCSRMULTD(OPT, M, N, K, A, JA, IA, B, JB, IB, C, LDC);

RES = KML_SPARSE_ZCSRMULTD(OPT, M, N, K, A, JA, IA, B, JB, IB, C, LDC);

Parameters

Parameter

Type

Description

Input/Output

opt

Enumeration type kml_sparse_operation_t

Indicates whether to transpose.

  • opt = 0, C = alpha * A * B + beta * C.
  • opt = 1: C = alpha * AT * B + beta * C.
  • opt = 2: C = alpha * AH * B + beta * C.

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. The value range is [1, MAX_KML_INT].

Input

k

Integer

Number of columns in matrix B. The value range is [1, MAX_KML_INT].

Input

a

  • For scsrmultd, a is a single-precision floating-point array.
  • For dcsrmultd, a is a double-precision floating-point array.
  • For ccsrmultd, a is a single-precision complex number array.
  • For zcsrmultd, a is a double-precision complex number array.

Array values storing non-zero elements of matrix A in the CSR format

Input

ja

Integer array

Array columns in the CSR format, which contains the column indices for non-zero elements in matrix A

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

b

  • For scsrmultd, b is a single-precision floating-point array.
  • For dcsrmultd, b is a double-precision floating-point array.
  • For ccsrmultd, b is a single-precision complex number array.
  • For zcsrmultd, b is a double-precision complex number array.

Array values storing non-zero elements of matrix B in the CSR format.

Input

jb

Integer array

Array columns in the CSR format, which contains the column indices for non-zero elements in matrix B.

Input

ib

Integer array

Array containing row indices of elements in matrix B. 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

  • For scsrmultd, c is a single-precision floating-point array.
  • For dcsrmultd, c is a double-precision floating-point array.
  • For ccsrmultd, c is a single-precision complex number array.
  • For zcsrmultd, c is a double-precision complex number array.

Array of matrix C

Output

ldc

Integer

Leading dimension of dense matrix C. ldc*k MAX_KML_INT

Input

The function does not verify the integrity of parameters. The interface caller must ensure that the elements in ia, ja, ib, and jb 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 k = 3; 
    float a[4] = {1, 5, 4, 5}; 
    KML_INT ja[4] = {3, 1, 1, 1}; 
    KML_INT ia[4] = {1, 3, 4, 5}; 
    float b[4] = {9, 4, 2, 8}; 
    KML_INT jb[4] = {2, 3, 1, 1}; 
    KML_INT ib[4] = {1, 3, 4, 5}; 
    float c[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; 
    KML_INT ldc = 3; 
    kml_sparse_status_t status = kml_sparse_scsrmultd(opt, m, n, k, a, ja, ia, b, jb, ib, c, ldc); 
    /* 
     *  Output c: 
     *     8.00  0.00  0.00  45.00  36.00  45.00  20.00  16.00  20.00 
     *  
     */

Fortran interface:

    INTEGER(C_INT) :: OPT = KML_SPARSE_OPERATION_NON_TRANSPOSE 
    INTEGER(C_INT) :: M = 3 
    INTEGER(C_INT) :: N = 3 
    INTEGER(C_INT) :: K = 3 
    REAL(C_FLOAT) :: A(4), B(4), C(9) 
    INTEGER(C_INT) :: JA(4), IA(4), JB(4), IB(4) 
    INTEGER(C_INT) :: LDC = 3 
    INTEGER(C_INT) :: STATUS  
    DATA A/1, 5, 4, 5/ 
    DATA B/9, 4, 2, 8/ 
    DATA C/0, 0, 0, 0, 0, 0, 0, 0, 0/ 
    DATA JA/3, 1, 1, 1/ 
    DATA IA/1, 3, 4, 5/ 
    DATA JB /2, 3, 1, 1/ 
    DATA IB /1, 3, 4, 5/ 
    STATUS = KML_SPARSE_SCSRMULTD(OPT, M, N, K, A, JA, IA, B, JB, IB, C, LDC) 
    ! 
    !  OUTPUT C: 
    !     8.00  0.00  0.00  45.00  36.00  45.00  20.00  16.00  20.00 
    !