SINTEF / Splipy

Spline modelling made easy.
GNU General Public License v3.0
102 stars 18 forks source link

From left evaluations crash on periodic basis #66

Closed VikingScientist closed 6 years ago

VikingScientist commented 6 years ago
from splipy import BSplineBasis

b = BSplineBasis(3, [-1,0,0,1,2,3,4,4,5], periodic=0)
b.evaluate(t=0, d=1, from_right=False)

Crashes with Segmentation fault from cython evaluation call.

Correct behavior should wrap this evaluation point to t=4 which causes no crash.

TheBB commented 6 years ago

In this line https://github.com/sintefmath/Splipy/blob/master/splipy/basis_eval.pyx#L97

mu is 0, p is 3 and j is 1. Since all types are unsigned ints, the value of k wraps around to 4294967294.

I'm not familiar enough with the algorithm to say which of these values are wrong though.

VikingScientist commented 6 years ago

I think line 74 is at fault. The floating point modulus operator wraps the evaluation point into the range [start, end), which really should be (start, end] in the case of left-limit evaluation.

VikingScientist commented 6 years ago

The bug is actually even more frequent than the first code seem to suggest. It happens with no derivatives and no periodicity:

from splipy import BSplineBasis

b = BSplineBasis(3, [0,0,0,1,2,3,4,4,4])
b.evaluate(t=0, d=0, from_right=False)

One should never get to line 97 which you linked to, and mu=0 makes no sense; mu=p is the lowest allowed value.