mirror of
https://github.com/stevenrobertson/cuburn.git
synced 2025-02-05 11:40:04 -05:00
Improve spline loading
This commit is contained in:
parent
fb5bdc2a9f
commit
3436291eb6
@ -8,13 +8,21 @@ class SplEval(object):
|
||||
# If a single value is passed, normalize to a constant set of knots
|
||||
if isinstance(knots, (int, float)):
|
||||
knots = [-0.1, knots, 0.0, knots, 1.0, knots, 1.1, knots]
|
||||
elif not np.all(np.diff(np.float32(np.asarray(knots))[::2]) > 0):
|
||||
raise ValueError("Spline times are non-monotonic. (Use "
|
||||
"nextafterf()-spaced times to anchor tangents.)")
|
||||
|
||||
# If stabilizing knots are missing before or after the edges of the
|
||||
# [0,1] interval, add them. TODO: choose better knots
|
||||
# [0,1] interval, add them. We choose knots that preserve the first
|
||||
# differential, which is probably what is expected when two knots are
|
||||
# present but may be less accurate for three. Of course, one can just
|
||||
# add stabilizing knots to the genome to change this.
|
||||
if knots[0] >= 0:
|
||||
knots = [-0.1, knots[1]] + knots
|
||||
m = (knots[3] - knots[1]) / (knots[2] - knots[0])
|
||||
knots = [-0.1, knots[1] + -0.1 * m] + knots
|
||||
if knots[-2] <= 1:
|
||||
knots.extend([1.1, knots[-1]])
|
||||
m = (knots[-1] - knots[-3]) / (knots[-2] - knots[-4])
|
||||
knots.extend([1.1, knots[-1] + 0.1 * m])
|
||||
|
||||
self.knots = np.zeros((2, len(knots)/2))
|
||||
self.knots.T.flat[:] = knots
|
||||
|
Loading…
Reference in New Issue
Block a user