Skip to content

Commit

Permalink
Bit of input validation. assert is not for this!
Browse files Browse the repository at this point in the history
  • Loading branch information
duetosymmetry committed May 17, 2019
1 parent f3b6db4 commit 55dbad4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
13 changes: 8 additions & 5 deletions qnm/cached.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ def mode_pickle_path(s, l, m, n):
"""

assert l >= l_min(s, m), ("l={} must be >= l_min={}"
.format(l, l_min(s, m)))
if not (l >= l_min(s, m)):
raise ValueError("l={} must be >= l_min={}"
.format(l, l_min(s, m)))


s_sign = '-' if (s<0) else ''
Expand Down Expand Up @@ -266,10 +267,12 @@ def __call__(self, s, l, m, n,
"""

assert l >= l_min(s, m), ("l={} must be >= l_min={}"
.format(l, l_min(s, m)))
if not (l >= l_min(s, m)):
raise ValueError("l={} must be >= l_min={}"
.format(l, l_min(s, m)))

assert n >= 0, ("n={} must be non-negative".format(n))
if not (n >= 0):
raise ValueError("n={} must be non-negative".format(n))

if compute_if_not_found is None:
compute_if_not_found = self.compute_if_not_found
Expand Down
7 changes: 3 additions & 4 deletions qnm/schwarzschild/overtonesequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,9 @@ def __init__(self, *args, **kwargs):
self.r_N = kwargs.get('r_N', 0.j)

# TODO check that values make sense!!!
assert self.l >= l_min(self.s, 0), ("l={} must be >= "
"l_min={}".format(
self.l,
l_min(self.s, 0)))
if not (self.l >= l_min(self.s, 0)):
raise ValueError("l={} must be >= l_min={}"
.format(self.l, l_min(self.s, 0)))

# We know the Schwarzschild separation constant analytically
self.A = swsphericalh_A(self.s, self.l, 0)
Expand Down
20 changes: 10 additions & 10 deletions qnm/spinsequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ def __init__(self, *args, **kwargs):
self.r_N = kwargs.get('r_N', 0.j)

# TODO check that values make sense!!!
assert self.a_max < 1., ("a_max={} must be < 1.".format(self.a_max))
assert self.l >= l_min(self.s, self.m), ("l={} must be "
">= l_min={}".format(
self.l,
l_min(self.s, self.m)))
if not (self.a_max < 1.):
raise ValueError("a_max={} must be < 1.".format(self.a_max))
if not (self.l >= l_min(self.s, self.m)):
raise ValueError("l={} must be >= l_min={}".format(
self.l, l_min(self.s, self.m)))

# Create array of a's, omega's, and A's
self.a = []
Expand Down Expand Up @@ -338,12 +338,10 @@ def __call__(self, a, store=False):
:func:`qnm.angular.C_and_sep_const_closest`.
"""

# TODO Make sure that interpolants have been built

# TODO validate input, 0 <= a < 1.
# TODO if a > a_max then extend
# TODO take parameter of whether to solve at guess or not

if not ((isinstance(a, float) or isinstance(a, int))
and (a >= 0.) and (a < 1.)):
raise ValueError("a={} is not a float in the range [0,1)".format(a))

# If this was a previously computed value, just return the
# earlier results
Expand All @@ -352,6 +350,8 @@ def __call__(self, a, store=False):

return self.omega[a_ind], self.A[a_ind], self.C[a_ind]

# TODO Make sure that interpolants have been built

o_r = self._interp_o_r(a)
o_i = self._interp_o_i(a)

Expand Down

0 comments on commit 55dbad4

Please sign in to comment.