|GNU Octave Manual Version 3|
by John W. Eaton, David Bateman, Søren Hauberg
Paperback (6"x9"), 568 pages
RRP £24.95 ($39.95)
188.8.131.52 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.
.^ 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; # sparse a2 = s .^ s; # full a3 = s .^ -2; # full, with Infs a4 = s ./ 2; # sparse a5 = 2 ./ s; # full, with Infs a6 = 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
s .^ s is a full matrix.
s .^ -2 involves terms like
0 .^ -2 which
is infinity, and so
s .^ -2 is equally a full matrix.
s ./ 2 has no problems, but
2 ./ s involves a large number of infinity terms and is a
full matrix. The case of
s ./ s involves terms like
0 ./ 0 which is a
NaN and so this is equally a full
matrix with the zero elements of s filled with
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|