Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
73e969a
add exception classes
bnavigator May 3, 2020
e07206a
migrate analysis to new exceptions
bnavigator May 3, 2020
1f356f2
migrate math to new exceptions
bnavigator May 3, 2020
a8edfb4
migrate synthesis to the new exceptions
bnavigator May 3, 2020
de6e3df
migrate transform to new exceptions
bnavigator May 4, 2020
37e45d1
unify exception call signature
bnavigator May 4, 2020
2f44753
exception messages extracted from docstrings
repagh May 5, 2020
89429ad
count exception messages in synthesis
repagh May 5, 2020
0fd2ea5
Only on indexError should we report unhandled code
repagh May 5, 2020
d1b9ab1
simplify negative info parameter checks
bnavigator May 5, 2020
dbf643b
actually test error message/info matching. Did reveal some fixes to
repagh May 5, 2020
42cfb49
only check docstring if provided
bnavigator May 5, 2020
b9bfaae
correct sb01bd copy and paste error
repagh May 5, 2020
8b5b8f9
rework exception docstring parser
bnavigator May 5, 2020
ed027fb
fix python 2 compatibility in regexp
bnavigator May 6, 2020
1877bc3
adding a more extensive check of docstring parsing
repagh May 6, 2020
d2f684d
extend the parser to warnings
bnavigator May 6, 2020
0e8d63c
update exceptions doc and test [skip ci]
bnavigator May 6, 2020
7ad1517
more work on exception and warning handling
bnavigator May 7, 2020
18f054e
more cleanup, including file attributes for source files
bnavigator May 7, 2020
a44c952
dont assertRaisesRegex in Py2
bnavigator May 7, 2020
d81c7d1
optional type
bnavigator May 7, 2020
ad24193
typo in range [skip ci]
bnavigator May 7, 2020
ec8c968
only parse docstring when iwarn or info
bnavigator May 7, 2020
c0b1069
bring synthesis.py closer to numpydoc
bnavigator May 7, 2020
ad28baa
minor cosmetics in math.py and synthesis.py docstrings [skip ci]
bnavigator May 7, 2020
82b653a
fix infospec detection regex
bnavigator May 7, 2020
8f60923
fix iwarn catchall and checkvars initialization
bnavigator May 7, 2020
91fb7e6
revert file mode changes for py files [skip ci]
bnavigator May 7, 2020
fd74855
comma in mb05nd docstring [skip ci]
bnavigator May 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
migrate math to new exceptions
  • Loading branch information
bnavigator committed May 3, 2020
commit 1f356f242fe6faece68fa609a60f6d86e4de994d
73 changes: 19 additions & 54 deletions slycot/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
# MA 02110-1301, USA.

from . import _wrapper
from .exceptions import SlycotError, SlycotParameterError, \
SlycotArithmeticError
import warnings

import numpy as np
Expand Down Expand Up @@ -236,10 +238,7 @@ def mb03rd(n, A, X=None, jobx='U', sort='N', pmax=1.0, tol=0.0):
jobx, sort, n, pmax, A, X, tol)

if info < 0:
fmt = "The following argument had an illegal value: '{}'"
e = ValueError(fmt.format(arg_list[-info - 1]))
e.info = info
raise e
raise SlycotParameterError(info, arg_list)
if jobx == 'N':
Xr = None
else:
Expand Down Expand Up @@ -306,12 +305,6 @@ def mb03vd(n, ilo, ihi, A):
scalar factors of the elementary reflectors used to form
the matrix Q_j, j = 1, ..., p. See FURTHER COMMENTS.

Raises
------

ValueError : e
e.info contains information about the exact type of exception

Further Comments
----------------

Expand Down Expand Up @@ -372,11 +365,8 @@ def mb03vd(n, ilo, ihi, A):

HQ, Tau, info = _wrapper.mb03vd(n, ilo, ihi, A)

if info != 0:
e = ValueError(
"Argument '{}' had an illegal value".format(arg_list[-info-1]))
e.info = info
raise e
if info < 0:
raise SlycotParameterError(info, arg_list)
return (HQ, Tau)


Expand Down Expand Up @@ -423,12 +413,6 @@ def mb03vy(n, ilo, ihi, A, Tau, ldwork=None):
3D array with same shape as A. Q[:n,:n,j-1] contains the
N-by-N orthogonal matrix Q_j, j = 1, ..., p.

Raises
------

ValueError :
e.info contains the number of the argument that was invalid

"""

hidden = ' (hidden by the wrapper)'
Expand All @@ -442,11 +426,8 @@ def mb03vy(n, ilo, ihi, A, Tau, ldwork=None):

Q, info = _wrapper.mb03vy(n, ilo, ihi, A, Tau, ldwork)

if info != 0:
e = ValueError(
"Argument '{}' had an illegal value".format(arg_list[-info-1]))
e.info = info
raise e
if info < 0:
raise SlycotParameterError(info, arg_list)

return Q

Expand Down Expand Up @@ -562,12 +543,6 @@ def mb03wd(job, compz, n, ilo, ihi, iloz, ihiz, H, Q, ldwork=None):
If JOB = 'S', the eigenvalues are stored in the same order
as on the diagonal of the Schur form returned in H.

Raises
------

ValueError : e
e.info contains information about the exact type of exception

"""
hidden = ' (hidden by the wrapper)'
arg_list = ['job', 'compz', 'n', 'p' + hidden,
Expand All @@ -585,10 +560,7 @@ def mb03wd(job, compz, n, ilo, ihi, iloz, ihiz, H, Q, ldwork=None):
job, compz, n, ilo, ihi, iloz, ihiz, H, Q, ldwork)

if info < 0:
e = ValueError(
"Argument '{}' had an illegal value".format(arg_list[-info-1]))
e.info = info
raise e
raise SlycotParameterError(info, arg_list)
elif info > 0:
warnings.warn(("failed to compute all the eigenvalues {ilo} to {ihi} "
"in a total of 30*({ihi}-{ilo}+1) iterations "
Expand Down Expand Up @@ -684,17 +656,16 @@ def mb05md(a, delta, balanc='N'):
VAL = VALr
return (Ar, Vr, Yr, VAL)
elif INFO < 0:
error_text = "The following argument had an illegal value: " \
+ arg_list[-INFO-1]
raise SlycotParameterError(INFO, arg_list)
elif INFO > 0 and INFO <= n:
error_text = "Incomplete eigenvalue calculation, missing %i eigenvalues" % INFO
raise SlycotArithmeticError("Incomplete eigenvalue calculation, "
"missing {} eigenvalues".format(INFO),
INFO)
elif INFO == n+1:
error_text = "Eigenvector matrix singular"
raise SlycotArithmeticError("Eigenvector matrix singular", INFO)
elif INFO == n+2:
error_text = "A matrix defective"
e = ValueError(error_text)
e.info = INFO
raise e
raise SlycotArithmeticError("Matrix A is defective, "
"possibly due to rounding errors.", INFO)


def mb05nd(a, delta, tol=1e-7):
Expand Down Expand Up @@ -729,13 +700,10 @@ def mb05nd(a, delta, tol=1e-7):
if out[-1] == 0:
return out[:-1]
elif out[-1] < 0:
error_text = "The following argument had an illegal value: " \
+ arg_list[-out[-1]-1]
raise SlycotParameterError(out[-1], arg_list)
elif out[-1] == n+1:
error_text = "Delta too large"
e = ValueError(error_text)
e.info = out[-1]
raise e
raise SlycotError("Delta too large", out[-1])



def mc01td(dico, dp, p):
Expand Down Expand Up @@ -781,10 +749,7 @@ def mc01td(dico, dp, p):
'IWARN', 'INFO']
(dp_out, stable_log, nz, iwarn, info) = _wrapper.mc01td(dico, dp, p)
if info < 0:
fmt = "The following argument had an illegal value: '{}'"
e = ValueError(fmt.format(arg_list[-info - 1]))
e.info = info
raise e
raise SlycotParameterError(info, arg_list)
if info == 1:
warnings.warn('entry P(x) is the zero polynomial.')
if info == 2:
Expand Down