Suppress error warnings from Cythonized code

asked 2016-12-14 01:29:38 +0100

updated 2016-12-14 01:30:11 +0100

The following Python code

n = 6.58
c0 = 1.1275
l = c0 - c0^(n+1)/(n+1)

c1 = 0.832857588520877

def f(c):
  return real( 1 / sqrt( c - c^(n+1)/(n+1) - l ) )

c = var('c')
integral = numerical_integral( f(c), ( c1, c0 ) )

print(integral)

gives an error message along with a numeric result

Exception KeyError: (3,) in 'sage.gsl.integration.c_ff' ignored
(1.7927361507678317, 1.5185983395728818e-06)

The numeric result matches an evaluation in Mathemtica, so I'd just like to suppress the error message. Since it arises in the Cythonized GSL C library, regular Python error handling with try/except or the warnings module doesn't appear able to do so.

The error message will go away if I add a small amount like 10-10 to the lower integration limit, but I'd like to know in general how to handle errors arising in Cythonized code.

edit retag flag offensive close merge delete