Example #1
0
def test_add():
    N, C, H, W = 2, 3, 4, 5
    a = np.random.random((N, C, H, W))
    b = np.random.random((N, C, H, W))
    c = np.random.random((N, C, H, W))
    l = L.Add([a, b], "op")
    l.reshape()
    l.forward()
    assert np.allclose(a + b, l.Y)
Example #2
0
def test_add5():
    N, C, H, W = 2,3,4,5
    a = np.random.random((N, C, H, W))
    b = np.random.random((N, C, H, W))
    c = np.random.random((N, C, H, W))
    l = L.Add(a, b, c, "add5")
    assert l.name == "/add5"
    l.reshape()
    l.forward()
    assert np.allclose(a + b + c, l.Y)
Example #3
0
def test_add2():
    N, C, H, W = 2, 3, 4, 5
    a = np.random.random((N, C, H, W))
    b = np.random.random((N, C, H, W))
    c = np.random.random((N, C, H, W))
    data = L.Data([a, b, c], "data")
    [la, lb, lc] = data()
    l = L.Add([la, lb, lc], "op")
    l.reshape()
    l.forward()
    assert np.allclose(a + b + c, l.Y)
    l.dY = np.random.random(l.Y.shape)
    l.backward()
    for i in range(3):
        assert np.allclose(l.dX[i], l.dY)