[Numpy-discussion] How to deal with NAN and co in C extension to numpy/scipy ?

David Cournapeau david at ar.media.kyoto-u.ac.jp
Wed Nov 22 04:45:45 CST 2006


Hi,

    I am about to release some code to compute LPC coefficients (Auto 
regressive modeling, using Levinson Durbin algorithm for autocorrelation 
matrix inversion), and I was wondering how to handle cases of divide by 
0, or values really near 0.

    I understand this is a complex issue, and I admittedly have no 
knowledge about it except some generalities; there are versions of 
Levinson Durbin which handles bad condition numbers (for people not 
familiar with LPC coding, levinson durbin is a recursive algorithm to 
inverse a symmetric Toeplitz matrix; the complexity becomes O(N^2) 
instead of O(N^3)); but they are overkill for LPC coding, I think.

    The options I see are:

    - I don't care :)
    - Detecting values near zero, finish the computation anyway in C, 
and returns an error code to python, which would emit a warning.
    - Detecting values near zero, returns an error code which would 
results in a python exception ?

    In this latter cases, is it ok to returns to python arrays the 
values from the C function ? In matlab, for bad cases, it just returns 
NAN; is this appropriate ? How should I do it ?

    cheers,

    David


More information about the Numpy-discussion mailing list