"SparseArray" (Compiled Type)

"SparseArray"::[type,rank]

represents a sparse array composite type with elements of specified type and rank.

Details

  • "SparseArray" can be used in Typed and related constructs to specify a type.

Properties

  • With "SparseArray"::[type, rank], unspecified values are always taken to be zero and rank can only be 1 or 2.

Expression Conversions

    From Expressions

  • SparseArray expressions can be converted into compiled code elements with types created with "SparseArray".
  • To Expressions

  • Compiled code elements with types created with "SparseArray" can be converted into SparseArray expressions.

Examples

open allclose all

Basic Examples  (1)

"SparseArray" can be used as an input and output from a CompiledCodeFunction:

Scope  (1)

SparseArray properties may be used within CompiledCodeFunction:

This is equivalent to the "Density" property:

The function uses real arithmetic so that it works even when the total number of elements is too large for a machine-sized integer:

Neat Examples  (1)

Compute a power series of a sparse matrix:

This is equivalent to computing the square of a matrix:

Generate coefficients of the exponential function and use them to compute a matrix exponential:

The MatrixExp function is a better way to compute the exponential, but the power series result was close: