예제 #1
0
def test_recurrence_fun():
    from cntk.layers import Recurrence
    from cntk.ops import plus

    ####################################################
    # Test 1: sum-reduction over sequence
    ####################################################
    r = Fold(plus)
    r.update_signature(Sequence[Tensor[1]])
    data = [np.array([[2], [6], [4], [8], [6]])]  # simple sequence
    out = r(data)
    exp = [sum(data[0])]
    np.testing.assert_array_equal(out,
                                  exp,
                                  err_msg='Error in recurrence over plus')

    ####################################################
    # Test 2: max-pool over sequence
    ####################################################
    r = Fold(element_max)
    r.update_signature(Sequence[Tensor[2]])
    data = [np.array([[2, 1], [6, 3], [4, 2], [8, 1], [6,
                                                       0]])]  # simple sequence
    out = r(data)
    exp = [np.max(data[0], axis=0)]
    np.testing.assert_array_equal(
        out, exp, err_msg='Error in recurrence over element_max')
예제 #2
0
def test_recurrence_fun():
    from cntk.layers import Recurrence
    from cntk.ops import plus

    ####################################################
    # Test 1: sum-reduction over sequence
    ####################################################
    r = Fold(plus)
    r.update_signature(Sequence[Tensor[1]])
    data = [np.array([[2], [6], [4], [8], [6]])]   # simple sequence
    out = r(data)
    exp = [sum(data[0])]
    np.testing.assert_array_equal(out, exp, err_msg='Error in recurrence over plus')

    ####################################################
    # Test 2: max-pool over sequence
    ####################################################
    r = Fold(element_max)
    r.update_signature(Sequence[Tensor[2]])
    data = [np.array([[2,1], [6,3], [4,2], [8,1], [6,0]])]   # simple sequence
    out = r(data)
    exp = [np.max(data[0], axis=0)]
    np.testing.assert_array_equal(out, exp, err_msg='Error in recurrence over element_max')