Пример #1
0
    def test_setup_windows_partitions_window(self):
        nwindows = 5
        window = (0, 1)
        piecewisecheb = PiecewiseChebyshevApproximant(
            np.sin, window_breakpoints=np.linspace(*window, nwindows + 1))
        windows = piecewisecheb._setup_windows()

        np.random.seed(72)
        x = np.random.rand(101) * np.ptp(window) + window[0]
        masks = [piecewisecheb._mask_window(x, w) for w in windows]
        number_of_masks_contained = np.sum(masks, axis=0)
        self.assertTrue(np.all(number_of_masks_contained == 1))
Пример #2
0
 def test_call_accurately_approximates(self):
     window = (0, 20)
     piecewisecheb = PiecewiseChebyshevApproximant(
         np.sin, window_breakpoints=np.linspace(*window, 21), degree=12)
     x = np.linspace(window[0], window[1] - 0.1, 101)
     true = np.sin(x)
     approx = piecewisecheb(x)
     self.assertTrue(np.allclose(true, approx, **TOLS))
Пример #3
0
 def test_call_returns_correct_shape(self):
     window = (0, 20)
     piecewisecheb = PiecewiseChebyshevApproximant(
         np.sin, window_breakpoints=np.linspace(*window, 6))
     x = np.linspace(window[0], window[1] - 0.1, 101)
     true = np.sin(x)
     approx = piecewisecheb(x)
     self.assertEqual(true.shape, approx.shape)
Пример #4
0
 def test_call_raises_error_when_x_equal_to_max_window(self):
     window = (0, 10)
     piecewisecheb = PiecewiseChebyshevApproximant(
         np.sin, window_breakpoints=np.linspace(*window, 6))
     self.assertRaises(ValueError, piecewisecheb, window[1])
Пример #5
0
 def test_dtype_on_complex(self):
     piecewisecheb = PiecewiseChebyshevApproximant(
         lambda x: np.exp(1j * x), window_breakpoints=np.linspace(0, 1, 6))
     self.assertEqual(piecewisecheb._dtype.name, 'complex128')
Пример #6
0
 def test_dtype_on_float(self):
     piecewisecheb = PiecewiseChebyshevApproximant(
         np.sin, window_breakpoints=np.linspace(0, 1, 6))
     self.assertEqual(piecewisecheb._dtype.name, 'float64')
Пример #7
0
 def test_setup_approximants_generates_approximants(self):
     piecewisecheb = PiecewiseChebyshevApproximant(
         np.sin, window_breakpoints=np.linspace(0, 1, 6))
     approximants = piecewisecheb._setup_approximants()
     for approximant in approximants:
         self.assertTrue(isinstance(approximant, ChebyshevApproximant))
Пример #8
0
 def test_setup_windows_splits_into_n_windows(self):
     nwindows = 5
     piecewisecheb = PiecewiseChebyshevApproximant(
         np.sin, window_breakpoints=np.linspace(0, 1, nwindows + 1))
     windows = piecewisecheb._setup_windows()
     self.assertEqual(len(windows), nwindows)
Пример #9
0
 def test_mask_window(self):
     window = (0, 1)
     x = np.linspace(0, 2, 101)
     mask = PiecewiseChebyshevApproximant._mask_window(x, window)
     self.assertLess(x[mask].max(), 1.0)
     self.assertGreaterEqual(x[~mask].min(), 1.0)