denseToSp#

Purpose#

Converts a dense matrix to a sparse matrix.

Format#

x_sparse = denseToSp(x, eps)#
Parameters:
  • x (MxN matrix) – Dense data matrix.

  • eps (scalar) – elements of x whose absolute values are less than or equal to eps will be treated as zero.

Returns:

x_sparse (MxN sparse matrix) – Sparse matrix converted from x.

Examples#

// Declare 'x_sparse' as a sparse matrix
sparse matrix x_sparse;

x = { 0.01 0.00 0.01 1.00,
      0.00 4.00 0.02 0.00,
      0.00 0.01 0.00 0.00,
      0.02 0.00 -2 0.00 };

/*
** Create a sparse matrix 'x_sparse' from 'x' and set all elements
** less than 0.04 equal to 0
*/
x_sparse = denseToSp(x, 0.04);

After the code above, x_sparse will be a matrix in sparse matrix format equivalent to :

0.00   0.00   0.00   1.00
0.00   4.00   0.00   0.00
0.00   0.00   0.00   0.00
0.00   0.00  -2.00   0.00

Remarks#

A dense matrix is just a normal format matrix.

Since sparse matrices are strongly typed in GAUSS, x_sparse must be defined as a sparse matrix before the call to denseToSp().

See also

Functions spCreate(), spDenseSubmat(), spToDense()