示例#1
0
 def test_nan(self):
     # bail out early if the input data contains nans
     x = np.arange(10, dtype=float)
     y = x**3
     w = np.ones_like(x)
     # also test LSQUnivariateSpline [which needs explicit knots]
     spl = UnivariateSpline(x, y, check_finite=True)
     t = spl.get_knots()[3:4]  # interior knots w/ default k=3
     y_end = y[-1]
     for z in [np.nan, np.inf, -np.inf]:
         y[-1] = z
         assert_raises(ValueError, UnivariateSpline,
                 **dict(x=x, y=y, check_finite=True))
         assert_raises(ValueError, InterpolatedUnivariateSpline,
                 **dict(x=x, y=y, check_finite=True))
         assert_raises(ValueError, LSQUnivariateSpline,
                 **dict(x=x, y=y, t=t, check_finite=True))
         y[-1] = y_end  # check valid y but invalid w
         w[-1] = z
         assert_raises(ValueError, UnivariateSpline,
                 **dict(x=x, y=y, w=w, check_finite=True))
         assert_raises(ValueError, InterpolatedUnivariateSpline,
                 **dict(x=x, y=y, w=w, check_finite=True))
         assert_raises(ValueError, LSQUnivariateSpline,
                 **dict(x=x, y=y, t=t, w=w, check_finite=True))
示例#2
0
 def test_linear_1d(self):
     x = [1,2,3]
     y = [0,2,4]
     lut = UnivariateSpline(x,y,k=1)
     assert_array_almost_equal(lut.get_knots(),[1,3])
     assert_array_almost_equal(lut.get_coeffs(),[0,4])
     assert_almost_equal(lut.get_residual(),0.0)
     assert_array_almost_equal(lut([1,1.5,2]),[0,1,2])
示例#3
0
 def test_increasing_x(self):
     xx = np.arange(10, dtype=float)
     yy = xx**3
     x = np.arange(10, dtype=float)
     x[1] = x[0]
     y = x**3
     w = np.ones_like(x)
     # also test LSQUnivariateSpline [which needs explicit knots]
     spl = UnivariateSpline(xx, yy, check_finite=True)
     t = spl.get_knots()[3:4]  # interior knots w/ default k=3
     assert_raises(ValueError, UnivariateSpline,
             **dict(x=x, y=y, check_finite=True))
     assert_raises(ValueError, InterpolatedUnivariateSpline,
             **dict(x=x, y=y, check_finite=True))
     assert_raises(ValueError, LSQUnivariateSpline,
             **dict(x=x, y=y, t=t, w=w, check_finite=True))
示例#4
0
 def test_increasing_x(self):
     xx = np.arange(10, dtype=float)
     yy = xx**3
     x = np.arange(10, dtype=float)
     x[1] = x[0]
     y = x**3
     w = np.ones_like(x)
     # also test LSQUnivariateSpline [which needs explicit knots]
     spl = UnivariateSpline(xx, yy, check_finite=True)
     t = spl.get_knots()[3:4]  # interior knots w/ default k=3
     assert_raises(ValueError, UnivariateSpline,
             **dict(x=x, y=y, check_finite=True))
     assert_raises(ValueError, InterpolatedUnivariateSpline,
             **dict(x=x, y=y, check_finite=True))
     assert_raises(ValueError, LSQUnivariateSpline,
             **dict(x=x, y=y, t=t, w=w, check_finite=True))
示例#5
0
 def test_strictly_increasing_x(self):
     # Test the x is required to be strictly increasing for
     # UnivariateSpline if s=0 and for InterpolatedUnivariateSpline,
     # but merely increasing for UnivariateSpline if s>0
     # and for LSQUnivariateSpline; see gh-8535
     xx = np.arange(10, dtype=float)
     yy = xx**3
     x = np.arange(10, dtype=float)
     x[1] = x[0]
     y = x**3
     w = np.ones_like(x)
     # also test LSQUnivariateSpline [which needs explicit knots]
     spl = UnivariateSpline(xx, yy, check_finite=True)
     t = spl.get_knots()[3:4]  # interior knots w/ default k=3
     UnivariateSpline(x=x, y=y, w=w, s=1, check_finite=True)
     LSQUnivariateSpline(x=x, y=y, t=t, w=w, check_finite=True)
     assert_raises(ValueError, UnivariateSpline,
                   **dict(x=x, y=y, s=0, check_finite=True))
     assert_raises(ValueError, InterpolatedUnivariateSpline,
                   **dict(x=x, y=y, check_finite=True))