kml_sparse_?doti
Compute the dot product of real vectors (Euclidean space).
res = x[0] * y[indx[0]] + x[1] * y[indx[1]] + ... + x[nz-1] * y[indx[nz-1]]
Interface Definition
C interface:
kml_sparse_status_t kml_sparse_sdoti(const KML_INT nz, const float *x,const KML_INT *indx, const float *y, float *doti);
kml_sparse_status_t kml_sparse_ddoti(const KML_INT nz, const double *x,const KML_INT *indx, const double *y, double *doti);
Fortran interface:
RES = KML_SPARSE_SDOTI(NZ, X, INDX, Y, DOTI);
RES = KML_SPARSE_DDOTI(NZ, X, INDX, Y, DOTI);
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
nz |
Integer |
Number of elements in the x and indx arrays. |
Input |
x |
|
Array x for storing non-zero elements. The size is at least nz. |
Input |
indx |
Integer array |
indx[i] indicates the serial number of the i-th element in the x array in the dense vector. The array size is at least nz. |
Input |
y |
|
Array y. The size is at least max(indx[i]). |
Input |
doti |
|
Dot product of x and y. |
Input/Output |
Return Value
Function execution status. The enumeration type is kml_sparse_status_t.
Dependencies
C: "kspblas.h"
Fortran: "kspblas.f03"
Examples
C interface:
KML_INT nz = 2;
float doti = 0;
KML_INT indx[2] = {1, 2};
float x[2] = {1, 3};
float y[4] = {-1, 1, 5, 3};
kml_sparse_status_t status = kml_sparse_sdoti(nz, x, indx, y, &doti);
/*
* Output doti:
* 16.000000
*/
Fortran interface:
INTEGER(C_INT) :: NZ = 2
REAL(C_FLOAT), TARGET :: DOTI
TYPE(C_PTR) :: PDOTI
INTEGER(C_INT) :: STATUS
INTEGER(C_INT) INDX(2)
REAL(C_FLOAT) X(2)
REAL(C_FLOAT) Y(2)
DATA INDX/1, 2/
DATA X/1, 3/
DATA Y/-1, 1, 5, 3/
PDOTI = C_LOC(DOTI)
STATUS = KML_SPARSE_SDOTI(NZ, X, INDX, Y, PDOTI)
/*
* OUTPUT DOTI:
* 16.000000
*/