octave-maintainers
[Top][All Lists]

## Re: inverse of singular sparse matrix

 From: Rik Subject: Re: inverse of singular sparse matrix Date: Fri, 10 May 2019 13:54:02 -0700

On 05/10/2019 01:07 AM, address@hidden wrote:
 Subject: What should the inverse of a singular sparse matrix be? From: Marco Caliari Date: 05/10/2019 01:07 AM
 List-Post: Precedence: list MIME-Version: 1.0 Message-ID: Content-Type: multipart/alternative; boundary="_000_PR1PR01MB5017C5B102796F53924F3D1C9E0C0PR1PR01MB5017eurp_" Message: 4

Dear maintainers,

it was recently fixed a nasty segmentation fault while trying to invert a sparse singular matrix

https://savannah.gnu.org/bugs/?56232

The question now is: what should the result of inv (A) be, with A a sparse singular matrix?

Current behavior:

A is a full singular matrix: both Octave and Matlab return inv (A) as a full matrix of the same dimension of A with Inf as elements, that is Inf (size (A)), plus a warning.

A is a sparse singular matrix: Matlab returns, in most cases, a *full* matrix with +/- Inf and/or NaN. Not clear to find a pattern. Octave returns a "division by zero" error.

My proposal, for A sparse singular, is to return a matrix with the same sparsity pattern of A, with Inf as elements, plus a warning. This solution has the advantage to not return a full useless matrix for a sparse singular input. The drawback is that the inverse of the sparse null matrix would be the input itself. In this specific case, I propose to turn the warning to a dedicated error. Additionally, I propose to extend this last behavior to the full null case. I cannot imagine a situation in which a user wants to invert the null matrix, except for a coding mistake.

I like the idea of splitting the special case of an empty matrix (probably a mistake, and, in any case, no useful value to return) from the more general singular matrix.

For the general singular matrix, I think preserving the sparsity but replacing all non-zero values with Inf is the most similar behavior to the dense case.  As such, it satisfies the principle of least astonishment (https://en.wikipedia.org/wiki/Principle_of_least_astonishment) in user interface design.

Looks good to me.

--Rik