bugGNU Octave - Bugs: bug #36437, chol2inv can't handle sparse matrix


bug #36437: chol2inv can't handle sparse matrix

Submitted by:  Nir Krakauer <nir_krakauer>
Submitted on:  Wed 09 May 2012 01:02:15 AM UTC  
Category: Octave FunctionSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Incorrect Result
Status: FixedAssigned to: None
Originator Name: Nir KrakauerOpen/Closed: Closed
Release: devOperating System: GNU/Linux

Add a New Comment(Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


Thu 11 Aug 2016 05:47:13 PM UTC, comment #5:

FYI - tests that rely on CHOLMOD should be marked with "testif HAVE_CHOLMOD", applied that change here


Mike Miller <mtmiller>
Project Administrator
Tue 09 Aug 2016 11:10:03 PM UTC, comment #4:

I have pushed the fix. Some notes of this fix:

  • sparse matrices that were previously identified as banded, but were banded AND lower/upper, are now upper or lower and not banded.
  • I noticed that non-sparse matrices do not check for banded matrices.



Note, I had to adjust the precision in one of your tests.

Carnë Draug <carandraug>
Project Member
Sat 06 Aug 2016 05:48:35 PM UTC, comment #3:

I added some tests, you can look at it at my repository:

Barbara Lócsi <bumi>
Tue 26 Jul 2016 12:53:33 PM UTC, comment #2:

I couldn't find any tests for chol2inv. Could you write some before I push this?

Carnë Draug <carandraug>
Project Member
Sat 12 Mar 2016 10:03:35 PM UTC, comment #1:

I can see it is still not working, (only the error is bit different)

The chol2inv function in sparse-chol.cc:526, requires the type of the matrix to be determined. If it is an upper or lower matrix than it determines the retval, but otherwise it gives this error.

This Y matrix is an upper matrix so i think the type of the matrix is determined incorrectly.
MatrixType.cc lines 340-364. If it is a banded matrix then the function won't check whether it is lower or upper matrix.
But in this case, this matrix (Y) is both banded and upper.

Temporarily I deleted the else from else if, so even thougth the matrix is both banded and upper/lower it will say it is upper/lower (before it said it is banded).
In this case there is no more error from chol2inv but it calculates wrong result.
The result of


,while the result of


I think the chol2inv calculates it wrongly.

It is: (inv(Y))' * inv(Y)
While it should be inv (Y'*Y)

(file #36613)

Barbara Lócsi <bumi>
Wed 09 May 2012 01:02:15 AM UTC, original submission:

chol2inv seems not to work when the input is a sparse upper triangular matrix. For example:

n = 10;
X = spdiags(ones(n, 1) * [1 2 1], [-1 0 1], n, n);
Y = chol(X);
Z = chol2inv(Y)
error: chol2inv: spchol2inv requires triangular matrix

On the other hand,
Z = chol2inv(full(Y))
returns the expected result

Nir Krakauer <nir_krakauer>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):

Attached Files
file #36613:  bug_36437.diff added by bumi (2KiB - application/octet-stream)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -unavailable- added by bumi (Updated the item)
  • -unavailable- added by mtmiller (Updated the item)
  • -unavailable- added by nir_krakauer (Submitted the item)

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.


    Please enter the title of George Orwell's famous dystopian book (it's a date):



    Follow 7 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Tue 09 Aug 2016 11:10:03 PM UTCcarandraugStatusConfirmed=>Fixed
    Sat 12 Mar 2016 10:03:35 PM UTCbumiAttached File-=>Added bug_36437.diff, #36613
    Mon 28 Oct 2013 02:33:21 AM UTCmtmillerCategoryNone=>Octave Function
      Item GroupNone=>Incorrect Result

    Back to the top

    Powered by Savane 3.1-cleanup1