Exemple #1
0
 def test_int(self):
     n = 64
     x = arange(n) * 2 * pi / n
     assert_array_almost_equal(diff(sin(x), -1), -cos(x))
     assert_array_almost_equal(diff(sin(x), -2), -sin(x))
     assert_array_almost_equal(diff(sin(x), -4), sin(x))
     assert_array_almost_equal(diff(2 * cos(2 * x), -1), sin(2 * x))
Exemple #2
0
 def test_period(self):
     for n in [17, 64]:
         x = arange(n) / float(n)
         assert_array_almost_equal(diff(sin(2 * pi * x), period=1),
                                   2 * pi * cos(2 * pi * x))
         assert_array_almost_equal(diff(sin(2 * pi * x), 3, period=1),
                                   -(2 * pi)**3 * cos(2 * pi * x))
Exemple #3
0
 def test_random_odd(self):
     for k in [0, 1, 2, 3, 4, 5, 6]:
         for n in [33, 65, 55]:
             f = random((n, ))
             af = sum(f, axis=0) / n
             f = f - af
             assert_almost_equal(sum(f, axis=0), 0.0)
             assert_array_almost_equal(diff(diff(f, k), -k), f)
             assert_array_almost_equal(diff(diff(f, -k), k), f)
Exemple #4
0
 def test_random_even(self):
     for n in [32, 64, 56]:
         f = random((n, ))
         af = sum(f, axis=0) / n
         f = f - af
         # zeroing Nyquist mode:
         f = diff(diff(f, 1), -1)
         assert_almost_equal(sum(f, axis=0), 0.0)
         assert_array_almost_equal(direct_hilbert(direct_ihilbert(f)), f)
         assert_array_almost_equal(hilbert(ihilbert(f)), f)
Exemple #5
0
 def test_expr_large(self):
     for n in [2048, 4096]:
         x = arange(n) * 2 * pi / n
         f = sin(x) * cos(4 * x) + exp(sin(3 * x))
         df = cos(x) * cos(4 * x) - 4 * sin(x) * sin(4 * x) + 3 * cos(
             3 * x) * exp(sin(3 * x))
         ddf = -17*sin(x)*cos(4*x)-8*cos(x)*sin(4*x)\
              - 9*sin(3*x)*exp(sin(3*x))+9*cos(3*x)**2*exp(sin(3*x))
         assert_array_almost_equal(diff(f), df)
         assert_array_almost_equal(diff(df), ddf)
         assert_array_almost_equal(diff(ddf, -1), df)
         assert_array_almost_equal(diff(f, 2), ddf)
Exemple #6
0
 def test_expr(self):
     for n in [64, 77, 100, 128, 256, 512, 1024, 2048, 4096, 8192][:5]:
         x = arange(n) * 2 * pi / n
         f = sin(x) * cos(4 * x) + exp(sin(3 * x))
         df = cos(x) * cos(4 * x) - 4 * sin(x) * sin(4 * x) + 3 * cos(
             3 * x) * exp(sin(3 * x))
         ddf = -17*sin(x)*cos(4*x)-8*cos(x)*sin(4*x)\
              - 9*sin(3*x)*exp(sin(3*x))+9*cos(3*x)**2*exp(sin(3*x))
         d1 = diff(f)
         assert_array_almost_equal(d1, df)
         assert_array_almost_equal(diff(df), ddf)
         assert_array_almost_equal(diff(f, 2), ddf)
         assert_array_almost_equal(diff(ddf, -1), df)
Exemple #7
0
 def test_sin(self):
     for n in [32, 64, 77]:
         x = arange(n) * 2 * pi / n
         assert_array_almost_equal(diff(sin(x)), cos(x))
         assert_array_almost_equal(diff(cos(x)), -sin(x))
         assert_array_almost_equal(diff(sin(x), 2), -sin(x))
         assert_array_almost_equal(diff(sin(x), 4), sin(x))
         assert_array_almost_equal(diff(sin(4 * x)), 4 * cos(4 * x))
         assert_array_almost_equal(diff(sin(sin(x))), cos(x) * cos(sin(x)))
Exemple #8
0
 def test_zero_nyquist(self):
     for k in [0, 1, 2, 3, 4, 5, 6]:
         for n in [32, 33, 64, 56, 55]:
             f = random((n, ))
             af = sum(f, axis=0) / n
             f = f - af
             # zeroing Nyquist mode:
             f = diff(diff(f, 1), -1)
             assert_almost_equal(sum(f, axis=0), 0.0)
             assert_array_almost_equal(diff(diff(f, k), -k), f)
             assert_array_almost_equal(diff(diff(f, -k), k), f)
Exemple #9
0
 def test_random_even(self):
     for k in [0, 2, 4, 6]:
         for n in [60, 32, 64, 56, 55]:
             f = random((n, ))
             af = sum(f, axis=0) / n
             f = f - af
             # zeroing Nyquist mode:
             f = diff(diff(f, 1), -1)
             assert_almost_equal(sum(f, axis=0), 0.0)
             assert_array_almost_equal(diff(diff(f, k), -k), f)
             assert_array_almost_equal(diff(diff(f, -k), k), f)
Exemple #10
0
 def test_definition(self):
     for n in [16, 17, 64, 127, 32]:
         x = arange(n) * 2 * pi / n
         assert_array_almost_equal(diff(sin(x)), direct_diff(sin(x)))
         assert_array_almost_equal(diff(sin(x), 2), direct_diff(sin(x), 2))
         assert_array_almost_equal(diff(sin(x), 3), direct_diff(sin(x), 3))
         assert_array_almost_equal(diff(sin(x), 4), direct_diff(sin(x), 4))
         assert_array_almost_equal(diff(sin(x), 5), direct_diff(sin(x), 5))
         assert_array_almost_equal(diff(sin(2 * x), 3),
                                   direct_diff(sin(2 * x), 3))
         assert_array_almost_equal(diff(sin(2 * x), 4),
                                   direct_diff(sin(2 * x), 4))
         assert_array_almost_equal(diff(cos(x)), direct_diff(cos(x)))
         assert_array_almost_equal(diff(cos(x), 2), direct_diff(cos(x), 2))
         assert_array_almost_equal(diff(cos(x), 3), direct_diff(cos(x), 3))
         assert_array_almost_equal(diff(cos(x), 4), direct_diff(cos(x), 4))
         assert_array_almost_equal(diff(cos(2 * x)),
                                   direct_diff(cos(2 * x)))
         assert_array_almost_equal(diff(sin(x * n / 8)),
                                   direct_diff(sin(x * n / 8)))
         assert_array_almost_equal(diff(cos(x * n / 8)),
                                   direct_diff(cos(x * n / 8)))
         for k in range(5):
             assert_array_almost_equal(diff(sin(4 * x), k),
                                       direct_diff(sin(4 * x), k))
             assert_array_almost_equal(diff(cos(4 * x), k),
                                       direct_diff(cos(4 * x), k))