octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #36562] Sparse matrix operations with NaN do n


From: Rik
Subject: [Octave-bug-tracker] [bug #36562] Sparse matrix operations with NaN do not follow IEEE standard
Date: Mon, 21 Nov 2016 16:44:24 +0000 (UTC)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0

Follow-up Comment #5, bug #36562 (project octave):

@Carlo: The memory problem already exists.  After one of the operations
involving NaN, every single element will become NaN and require storage.  In
fact, the situation will be worse than a full matrix because there will be the
extra overhead of the sparse matrix implementation.

In general, even without sparse_auto_mutate set to true, Octave will convert
to full for operations that are likely to result in a full matrix.  From the
documentation,


22.1.4.2 Return Types of Operators and Functions

The two basic reasons to use sparse matrices are to reduce the memory usage
and to not have
to do calculations on zero elements. The two are closely related in that the
computation
time on a sparse matrix operator or function is roughly linear with the number
of nonzero
elements.

Therefore, there is a certain density of nonzero elements of a matrix where it
no longer
makes sense to store it as a sparse matrix, but rather as a full matrix. For
this reason
operators and functions that have a high probability of returning a full
matrix will always
return one. For example adding a scalar constant to a sparse matrix will
almost always
make it a full matrix, and so the example,

speye (3) + 0
⇒
 1 0 0
0 1 0
0 0 1
returns a full matrix as can be seen.


For addition and subtraction, the sparse matrices are already converted to
full and the NaN is added/subtracted and the operation follows IEEE
guidelines.  For Sparse Matrix OPERATION Scalar NaN, the code would be easy to
modify to check for NaN and then return


NaN (size (Xsparse))


For Matrix OPERATION Matrix operations it becomes a bit annoying because one
would have to check for isnan() on every element.  This may be what Matlab
does.  Can you test the following?


xs = sparse ([1 0; 0 2]);
ys = sparse ([1 NaN; 0 0]);
xs .* ys





    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?36562>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]