GNU Octave Manual Version 3by John W. Eaton, David Bateman, Søren Hauberg Paperback (6"x9"), 568 pages ISBN 095461206X RRP £24.95 ($39.95) |

#### 20.1.6.3 Mathematical Considerations

Octave's implementation of sparse matrices tries to behave in exactly the same manner as for full matrices. However, there are some additional considerations needed in the use of sparse matrices, and also differences from other sparse matrix implementations.

Firstly, the `./`

and `.^`

operators must be used with care.
In Octave their behavior is consistent with full matrices, and is
different from sparse implementations in other products.

The following examples show how Octave's implementation behaves:

s = speye (4); a1 = s .^ 2;# sparsea2 = s .^ s;# fulla3 = s .^ -2;# full, with Infsa4 = s ./ 2;# sparsea5 = 2 ./ s;# full, with Infsa6 = s ./ s;# full, with NaNs

The first example of `s` raised to the power of 2 causes no
problems. However `s` raised element-wise to itself involves a
large number of terms `0 .^ 0`

which is 1. Therefore

is a full matrix.
`s` .^ `s`

Likewise

involves terms like `s` .^ -2`0 .^ -2`

which
is infinity, and so

is equally a full matrix.
`s` .^ -2

For the `./`

operator

has no problems, but
`s` ./ 2`2 ./ `

involves a large number of infinity terms and is a
full matrix. The case of `s`

involves terms like
`s` ./ `s``0 ./ 0`

which is a `NaN`

and so this is equally a full
matrix with the zero elements of `s` filled with `NaN`

values.

Calculations where the sign-bit of zero is important must not be performed using sparse matrices. The zeros of a sparse matrix are not stored, so their sign-bit is unknown. For example, the following calculation shows the lack of signed-zeros in the sparse matrix implementation:

a = 0 ./ [-1, 1; 1, -1]; b = 1 ./ a => -Inf Inf Inf -Inf c = 1 ./ sparse (a) => Inf Inf Inf Inf

Correcting this behavior for sparse matrices would require the storage of zero elements with a negative sign-bit, and this is not implemented for reasons of efficiency.

ISBN 095461206X | GNU Octave Manual Version 3 | See the print edition |