示例#1
0
    def test_real_valid_mode(self):
        a = array([3, 3, 5, 6, 8, 7, 9, 0, 1])
        b = array([3, 2, 1])
        d = array([24., 31., 41., 43., 49., 25., 12.])

        c = fftconvolve(a, b, 'valid')
        assert_array_almost_equal(c, d)

        # See gh-5897
        c = fftconvolve(b, a, 'valid')
        assert_array_almost_equal(c, d)
示例#2
0
 def test_random_data(self):
     np.random.seed(1234)
     a = np.random.rand(1233) + 1j * np.random.rand(1233)
     b = np.random.rand(1321) + 1j * np.random.rand(1321)
     c = fftconvolve(a, b, 'full')
     d = np.convolve(a, b, 'full')
     assert_(np.allclose(c, d, rtol=1e-10))
示例#3
0
 def test_2d_complex_same(self):
     a = array([[1 + 2j, 3 + 4j, 5 + 6j], [2 + 1j, 4 + 3j, 6 + 5j]])
     c = fftconvolve(a, a)
     d = array([[-3 + 4j, -10 + 20j, -21 + 56j, -18 + 76j, -11 + 60j],
                [10j, 44j, 118j, 156j, 122j],
                [3 + 4j, 10 + 20j, 21 + 56j, 18 + 76j, 11 + 60j]])
     assert_array_almost_equal(c, d)
示例#4
0
    def test_valid_mode(self):
        # See gh-5897
        a = array([3, 2, 1])
        b = array([3, 3, 5, 6, 8, 7, 9, 0, 1])
        expected = array([24., 31., 41., 43., 49., 25., 12.])

        out = fftconvolve(a, b, 'valid')
        assert_array_almost_equal(out, expected)

        out = fftconvolve(b, a, 'valid')
        assert_array_almost_equal(out, expected)

        a = array([3 - 1j, 2 + 7j, 1 + 0j])
        b = array([3 + 2j, 3 - 3j, 5 + 0j, 6 - 1j, 8 + 0j])
        expected = array([45. + 12.j, 30. + 23.j, 48 + 32.j])

        out = fftconvolve(a, b, 'valid')
        assert_array_almost_equal(out, expected)

        out = fftconvolve(b, a, 'valid')
        assert_array_almost_equal(out, expected)
示例#5
0
 def test_single_element(self):
     a = array([4967])
     b = array([3920])
     c = fftconvolve(a, b)
     assert_equal(c, a * b)
示例#6
0
 def test_zero_rank(self):
     a = array(4967)
     b = array(3920)
     c = fftconvolve(a, b)
     assert_equal(c, a * b)
示例#7
0
 def test_empty(self):
     # Regression test for #1745: crashes with 0-length input.
     assert_(fftconvolve([], []).size == 0)
     assert_(fftconvolve([5, 6], []).size == 0)
     assert_(fftconvolve([], [7]).size == 0)
示例#8
0
 def test_real_same_mode2(self):
     a = array([3, 3, 5, 6, 8, 7, 9, 0, 1])
     b = array([1, 2, 3])
     c = fftconvolve(a, b, 'same')
     d = array([9., 20., 25., 35., 41., 47., 39., 28., 2.])
     assert_array_almost_equal(c, d)
示例#9
0
 def test_2d_real_same(self):
     a = array([[1, 2, 3], [4, 5, 6]])
     assert_array_almost_equal(
         fftconvolve(a, a),
         array([[1, 4, 10, 12, 9], [8, 26, 56, 54, 36],
                [16, 40, 73, 60, 36]]))
示例#10
0
 def test_complex(self):
     x = array([1 + 1j, 2 + 2j, 3 + 3j])
     assert_array_almost_equal(fftconvolve(x, x),
                               [0 + 2j, 0 + 8j, 0 + 20j, 0 + 24j, 0 + 18j])
示例#11
0
 def test_real(self):
     x = array([1, 2, 3])
     assert_array_almost_equal(fftconvolve(x, x), [1, 4, 10, 12, 9.])