예제 #1
0
def test_1():
    x = np.linspace(0, 1, 5)

    x = x.astype('d')
    assert eq(np.cos(x), uf.cos(x))

    x = x.astype('f')
    assert eq(np.sin(x), uf.sin(x))
예제 #2
0
def test_2():
    fn = np.vectorize(lambda N, x: N * x)

    for N, x in ((1, 2.0),
                 ([[1], [2]], [1.0, 2.0, 3.0, 4.0]),
                 (1, [[1.0, 2.0], [3.0, 4.0]]),
                 ([[1], [2]], [[1.0, 2.0], [3.0, 4.0]])):
        assert eq(fn(N, x), uf.fn(N, x))

    N = 1
    for x in ([1, 2, 3, 4],
              np.ones(100),
              np.zeros(100)):
        assert eq(fn(N, x), uf.fn(N, x))
예제 #3
0
def test_2():
    np_fft2 = lambda _: np.apply_along_axis(nf.fft, -1, _)

    x = np.arange(16).reshape(4, 4)
    assert eq(fft2(x), np_fft2(x))

    x = np.random.rand(4, 4) + 1j * np.random.rand(4, 4)
    assert eq(fft2(x), np_fft2(x))

    x = np.random.rand(7, 7) + 1j * np.random.rand(7, 7)
    assert eq(fft2(x), np_fft2(x))

    x = np.random.rand(5, 8) + 1j * np.random.rand(5, 8)
    assert eq(fft2(x), np_fft2(x))

    x = np.random.rand(5) + 1j * np.random.rand(5)
    assert eq(fft2(x), np_fft2(x))
예제 #4
0
def test_1():
    x = [0, 1, 2, 3]
    assert eq(fft(x), nf.fft(x))

    x = [0, 1, 2, 3, 4]
    assert eq(fft(x), nf.fft(x))

    x = [0, 0, 0, 0]
    assert eq(fft(x), nf.fft(x))

    x = [5, 2, 3, 3 + 2j]
    assert eq(fft(x), nf.fft(x))

    x = np.arange(1000)
    assert eq(fft(x), nf.fft(x))

    x = np.random.rand(100) + 1j * np.random.rand(100)
    assert eq(fft(x), nf.fft(x))
예제 #5
0
def test_eigen():
    assert eq(square([[0, 0], [0, 0]]), np.array([[0, 0], [0, 0]]))

    assert eq(square([[1, 2], [3, 4]]), np.array([[0., 10.], [15., 22.]]))
예제 #6
0
def test_3():
    assert eq(uf.add_one([1, 2, 3]), [2, 3, 4])
    assert eq(uf.add_one([3, 2, 1]), [4, 3, 2])