From 532914dd600a7455c6667cd249065a5e5c9cc6b7 Mon Sep 17 00:00:00 2001 From: Benjamin Greiner Date: Sun, 17 May 2020 17:32:04 +0200 Subject: [PATCH] [skip ci] [WIP] override xerbla to raise exception --- slycot/CMakeLists.txt | 2 +- slycot/__init__.py | 5 +++++ slycot/exceptions.py | 8 ++++++++ slycot/src/XERBLA.f | 19 +++++++++++++++++++ slycot/src/_helper.pyf | 9 +++++++-- slycot/src/_wrapper.pyf | 25 ++++++++++++++++++------- 6 files changed, 58 insertions(+), 10 deletions(-) create mode 100644 slycot/src/XERBLA.f diff --git a/slycot/CMakeLists.txt b/slycot/CMakeLists.txt index c481cea6..140e89a2 100644 --- a/slycot/CMakeLists.txt +++ b/slycot/CMakeLists.txt @@ -104,7 +104,7 @@ set(FSOURCES src/delctg.f src/select.f src/SLCT_DLATZM.f src/SLCT_ZLATZM.f - src/ftruefalse.f + src/ftruefalse.f src/XERBLA.f ) set(F2PYSOURCE src/_wrapper.pyf) diff --git a/slycot/__init__.py b/slycot/__init__.py index 0c2b3c70..1b344e49 100644 --- a/slycot/__init__.py +++ b/slycot/__init__.py @@ -43,6 +43,11 @@ # Version information from .version import version as __version__ + # initialize error handling + from .exceptions import raise_xerbla + from . import _wrapper + _wrapper.raise_xerbla = raise_xerbla + from numpy.testing import Tester test = Tester().test bench = Tester().bench diff --git a/slycot/exceptions.py b/slycot/exceptions.py index f08bb3f6..7376e6e2 100644 --- a/slycot/exceptions.py +++ b/slycot/exceptions.py @@ -257,3 +257,11 @@ def raise_if_slycot_error(info, arg_list=None, docstring=None, checkvars=None): warn(SlycotWarning("Caught unhandled nonzero IWARN value {}" "".format(iwarn), iwarn, info)) + + +def raise_xerbla(srname, info): + """Overrides LAPACK XERBLA routine to raise Exception instead of exiting + """ + message = ("The argument number {1} to {0} had an illegal value." + "".format(srname, -info)) + raise SlycotParameterError(message, info) diff --git a/slycot/src/XERBLA.f b/slycot/src/XERBLA.f new file mode 100644 index 00000000..067867c6 --- /dev/null +++ b/slycot/src/XERBLA.f @@ -0,0 +1,19 @@ + SUBROUTINE XERBLA(SRNAME, INFO) +C +C SLYCOT +C Override LAPACK XERBLA routine to raise Python Exception instead of +C exiting the process +C +CF2PY INTENT(CALLBACK, HIDE) RAISE_XERBLA +C + CHARACTER*(*) SRNAME + INTEGER INFO +C + EXTERNAL RAISE_XERBLA +C + CALL RAISE_XERBLA(SRNAME, INFO) +C + RETURN +C + END +C \ No newline at end of file diff --git a/slycot/src/_helper.pyf b/slycot/src/_helper.pyf index ed59e106..ac97e723 100644 --- a/slycot/src/_helper.pyf +++ b/slycot/src/_helper.pyf @@ -6,5 +6,10 @@ subroutine ftruefalse(ftrue,ffalse) ! in src/ftruefalse.f logical intent(out) :: ffalse end subroutine ftruefalse -! This file was auto-generated with f2py (version:2). -! See http://cens.ioc.ee/projects/f2py2e/ +subroutine xerbla(srname,info) ! in src/XERBLA.f + use __user__routines + character*(*) :: srname + integer :: info + intent(callback) raise_xerbla + external raise_xerbla +end subroutine xerbla diff --git a/slycot/src/_wrapper.pyf b/slycot/src/_wrapper.pyf index 5a4c6784..e5518ef7 100644 --- a/slycot/src/_wrapper.pyf +++ b/slycot/src/_wrapper.pyf @@ -1,12 +1,23 @@ ! -*- f90 -*- ! Note: the context of this file is case sensitive. -python module _wrapper ! in - interface ! in :wrapper - include "analysis.pyf" - include "math.pyf" - include "synthesis.pyf" - include "transform.pyf" - include "_helper.pyf" +python module __user__routines + interface + subroutine raise_xerbla(srname,info) + intent(callback,hide) raise_xerbla + character*(*) :: srname + integer :: info + end subroutine raise_xerbla + end interface +end python module __user__routines + +python module _wrapper + interface + include "analysis.pyf" + include "math.pyf" + include "synthesis.pyf" + include "transform.pyf" + include "_helper.pyf" end interface end python module slycot +