Getting a warning "On entry to CGECON, parameter number 5 had an illegal value" using Armadillo with LAPACK

71 views Asked by At

Before I begin, this really is more of a warning than an error, since it appears my code still functions and gives the correct result, although it's rather annoying to get this message all the time with no way to suppress it.

Here is some example code that, as far as I can tell should replicate this warning. I'm running on MacOS with the latest versions of OpenBLAS, LAPACK, and Armadillo installed:

#include <iostream>
#include <armadillo>

int main() {
    arma::cx_mat input = {{ {3.628, -1.853}, {0.05084, -0.05331}, {-0.8368, 1.799}, {-0.124, 0.3518}, {-0.4013, 4.255e-08} },
                          { {0.08167, -0.05757}, {0.7587, 0.253}, {-0.07149, 0.1537}, {-0.01521, 0.04317}, {0.004557, -4.832e-10} },
                          { {-3.999, 2.819}, {-0.2127, 0.223}, {4.008, -6.466}, {0.4424, -1.255}, {1.708, -1.811e-07} },
                          { {-0.9691, 0.6831}, {-0.07403, 0.07762}, {0.7236, -1.555}, {0.9407, 0.1682}, {0.1246, -1.321e-08} },
                          { {-1.477, 1.041}, {0.01045, -0.01095}, {1.316, -2.828}, {0.05867, -0.1665}, {1.081, -8.551e-09} }};
    arma::cx_mat inverse = arma::inv(input, arma::inv_opts::allow_approx);
    double rc = arma::rcond(input);
    std::cout << "Inverse matrix:\n" << inverse << std::endl;
    std::cout << "RCOND: " << rc << std::endl;


    arma::cx_fmat input_f = {{ {3.628, -1.853}, {0.05084, -0.05331}, {-0.8368, 1.799}, {-0.124, 0.3518}, {-0.4013, 4.255e-08} },
                          { {0.08167, -0.05757}, {0.7587, 0.253}, {-0.07149, 0.1537}, {-0.01521, 0.04317}, {0.004557, -4.832e-10} },
                          { {-3.999, 2.819}, {-0.2127, 0.223}, {4.008, -6.466}, {0.4424, -1.255}, {1.708, -1.811e-07} },
                          { {-0.9691, 0.6831}, {-0.07403, 0.07762}, {0.7236, -1.555}, {0.9407, 0.1682}, {0.1246, -1.321e-08} },
                          { {-1.477, 1.041}, {0.01045, -0.01095}, {1.316, -2.828}, {0.05867, -0.1665}, {1.081, -8.551e-09} }};
    arma::cx_fmat inverse_f = arma::inv(input_f, arma::inv_opts::allow_approx);
    float rc_f = arma::rcond(input_f);
    std::cout << "Inverse matrix:\n" << inverse_f << std::endl;
    std::cout << "RCOND: " << rc_f << std::endl;
    return 0;
}

When compiled and run, this returns:

Inverse matrix:
    (+3.267e-01,+1.195e-01)    (-4.544e-03,-1.189e-02)    (+8.918e-02,+7.236e-03)    (+3.064e-02,-2.473e-03)    (-2.316e-02,+3.325e-02)
    (-2.913e-03,-1.703e-02)    (+1.179e+00,-4.259e-01)    (+4.745e-02,-5.144e-02)    (+3.078e-02,+1.052e-04)    (-8.457e-02,+7.673e-02)
    (+1.819e-01,+1.251e-01)    (+1.117e-01,-6.091e-02)    (+3.342e-01,+1.159e-01)    (-1.325e-01,+2.891e-01)    (-4.457e-01,-1.698e-01)
    (+8.388e-02,+5.002e-02)    (+6.566e-02,+2.982e-02)    (-2.059e-01,+3.544e-01)    (+6.955e-01,-5.141e-01)    (+2.761e-01,-4.822e-01)
    (+7.717e-04,+1.825e-01)    (-9.527e-03,+3.790e-01)    (-6.245e-01,+6.072e-01)    (-5.143e-01,-5.961e-01)    (+1.971e+00,-8.245e-01)

RCOND: 0.0206112
** On entry to CGECON, parameter number  5 had an illegal value
** On entry to CGECON, parameter number  5 had an illegal value
Inverse matrix:
    (+3.267e-01,+1.195e-01)    (-4.544e-03,-1.189e-02)    (+8.918e-02,+7.236e-03)    (+3.064e-02,-2.473e-03)    (-2.316e-02,+3.325e-02)
    (-2.913e-03,-1.703e-02)    (+1.179e+00,-4.259e-01)    (+4.745e-02,-5.144e-02)    (+3.078e-02,+1.050e-04)    (-8.457e-02,+7.673e-02)
    (+1.819e-01,+1.251e-01)    (+1.117e-01,-6.091e-02)    (+3.342e-01,+1.159e-01)    (-1.325e-01,+2.891e-01)    (-4.457e-01,-1.698e-01)
    (+8.388e-02,+5.002e-02)    (+6.566e-02,+2.982e-02)    (-2.059e-01,+3.544e-01)    (+6.955e-01,-5.141e-01)    (+2.761e-01,-4.822e-01)
    (+7.716e-04,+1.825e-01)    (-9.527e-03,+3.790e-01)    (-6.245e-01,+6.072e-01)    (-5.143e-01,-5.961e-01)    (+1.971e+00,-8.245e-01)

RCOND: 0

This isn't the only matrix for which this happens, it just happens to be one from a dataset I have that is throwing this message. Not all matrices do, and I can't seem to figure out what the difference is. Note that if you call the inv() function without arma::inv_opts::allow_approx, this returns the exact same answer without the warning. Additionally, if you make the matrix an arma::cx_mat rather than an arma::cx_fmat, the error goes away, regardless of the allow_approx option.

I've traced this back to LAPACK, where the file cgecon.f has the following code:

*     Test the input parameters.
*
      INFO = 0
      ONENRM = NORM.EQ.'1' .OR. LSAME( NORM, 'O' )
      IF( .NOT.ONENRM .AND. .NOT.LSAME( NORM, 'I' ) ) THEN
         INFO = -1
      ELSE IF( N.LT.0 ) THEN
         INFO = -2
      ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
         INFO = -4
      ELSE IF( ANORM.LT.ZERO .OR. SISNAN( ANORM ) ) THEN
         INFO = -5
      END IF
      IF( INFO.NE.0 ) THEN
         CALL XERBLA( 'CGECON', -INFO )
         RETURN
      END IF

The line CALL XERBLA just prints the error message shown, where -INFO is -(-5) or parameter 5 in the message. According to the documentation, this means the input parameter ANORM is either negative or nan. ANORM is supposed to be the 1-norm of the matrix (I've already checked and Armadillo call the function with NORM = '1'), and I can easily compute the 1-norm to be 14.59. Again, this doesn't seem to be a problem for a matrix of complex doubles, and it doesn't happen without the allow_approx argument.

Does anyone know what's going on here? It seems like I'm still getting the right result despite the error message, so it's not critical, but considering I have to evaluate hundreds of thousands of these inverses, it's a bit annoying that this error message gets printed so much to my terminal (and I'm sure it's not exactly fast to do so).

0

There are 0 answers