[Top][All Lists]

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

[Octave-bug-tracker] [bug #55710] svd may sometimes return -0 for exactl

From: Rik
Subject: [Octave-bug-tracker] [bug #55710] svd may sometimes return -0 for exactly zero singular values
Date: Thu, 14 Feb 2019 12:39:30 -0500 (EST)
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko

Update of bug #55710 (project octave):

                  Status:                    None => Confirmed              


Follow-up Comment #2:

Matlab doesn't display the negative sign for zero, so you need to infer it
from something like taking 1/x.

Here is a sample session from R2018b showing that Matlab is returning a -0.

n = 10;
A = randn(n);
A = triu(A);

A(1) = -0;
[U,s,V] = svd(A);
ans = -Inf

Also, for some reason this is dependent on the random values in A.  A more
interesting test is

n = 10;
for i = 1:20
  A = randn(n);
  A = triu(A);
  A(1) = -0;
  [U,S,V] = svd(A);
  tst(i) = (1/S(end) == -Inf);
fprintf ("-0 results: %d / 20\n", sum (tst));

This shows about half the time the results are -0 versus +0.

This occurs on both Matlab and Octave.

I'm pretty sure this will be found to be an upstream issue with LAPACK, but in
the meantime, we can probably do something about it.

The matrix S returned from the [U,S,V] is a diagonal matrix which in Octave
means it is stored in a space-efficient manner.  If we were to call abs(S)
before returning it would only require running abs() on the N elements of the
diagonal which would be exceedlingly quick.  Alternatively, we could fix
things up in the m-file with

S(S == 0) = 0;

which would replace any negative zeros with positive zeros.

@Tim: Is that an acceptable workaround?  Are all other singular values
guaranteed to be positive so that abs or the indexing trick would be enough?


Reply to this item at:


  Message sent via Savannah

reply via email to

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