Routines (alphabetical) > Routines: S > SPRSAB

# SPRSAB

The SPRSAB function performs matrix multiplication on two row-indexed sparse arrays created by SPRSIN. The routine computes all components of the matrix products, but only stores those values whose absolute magnitude exceeds the threshold value.

SPRSAB is based on the routine `sprstm` described in section 2.7 of Numerical Recipes in C: The Art of Scientific Computing (Second Edition), published by Cambridge University Press, and is used by permission. The difference between the two routines is that SPRSAB performs the matrix multiplication A*B rather than A*BT.

## Examples

; Begin by creating two arrays:
A = [[ 5.0, 0.0, 0.0, 1.0], $
[ 3.0, -2.0, 0.0, 1.0], $
[ 4.0, -1.0, 0.0, 2.0], $
[ 0.0, 3.0, 3.0, 1.0]]
B = [[ 1.0, 2.0, 3.0, 1.0], $
[ 3.0, -3.0, 0.0, 1.0], $
[-1.0, 3.0, 1.0, 2.0], $
[ 0.0, 3.0, 3.0, 1.0]]
; Convert the arrays to sparse array format before multiplying.
; The variable SPARSE holds the result in sparse array form:
sparse = SPRSAB(SPRSIN(A), SPRSIN(B))
; Restore the sparse array structure to full storage mode:
result = FULSTR(sparse)
; Print the result:
PRINT, 'result:'
PRINT, result
; Check this result by multiplying the original arrays:
exact = B # A
PRINT, 'exact:'
PRINT, exact

IDL prints:

result:

5.00000 13.0000 18.0000 6.00000

-3.00000 15.0000 12.0000 2.00000

1.00000 17.0000 18.0000 5.00000

6.00000 3.00000 6.00000 10.0000

exact:

5.00000 13.0000 18.0000 6.00000

-3.00000 15.0000 12.0000 2.00000

1.00000 17.0000 18.0000 5.00000

6.00000 3.00000 6.00000 10.0000

## Syntax

Result = SPRSAB( A, B [, /DOUBLE] [, THRESHOLD=value] )

## Return Value

The result is a row-indexed sparse array.

## Arguments

### A, B

Row-indexed sparse arrays created by the SPRSIN function.

Note: If SPRSAB is complex then only the real part is used for the computation.

## Keywords

### DOUBLE

Set this keyword to force the computation to be done in double-precision arithmetic.

### THRESHOLD

Use this keyword to set the criterion for deciding the absolute magnitude of the elements to be retained in sparse storage mode. For single-precision calculations, the default value is 1.0 X 10-7. For double-precision calculations, the default is 1.0 x 10-14.

## Version History

4.0 | Introduced

## See Also

FULSTR, LINBCG, SPRSAX, SPRSIN, SPRSTP, READ_SPR, WRITE_SPR