Beispiel #1
0
def test_non_cupy_sum():
    def fun(x, y):
        return sum([x, y])

    mat1 = cpr.randn(10, 11)
    mat2 = cpr.randn(10, 11)
    check_grads(fun)(mat1, mat2)
Beispiel #2
0
def test_concatenate_axis_1():
    A = cpr.randn(5, 6, 4)
    B = cpr.randn(5, 6, 4)

    def fun(x):
        return cp.concatenate((B, x, B), axis=1)

    check_grads(fun)(A)
Beispiel #3
0
def test_simple_concatenate():
    A = cpr.randn(5, 6, 4)
    B = cpr.randn(4, 6, 4)

    def fun(x):
        return cp.concatenate((A, x))

    check_grads(fun)(B)
Beispiel #4
0
def test_no_relation():
    with warnings.catch_warnings(record=True) as w:
        c = cpr.randn(3, 2)

        def fun(x):
            return c

        A = cpr.randn(3, 2)
        check_grads(fun)(A)
Beispiel #5
0
def test_where():
    def fun(x, y):
        b = cp.where(C, x, y)
        return b

    C = cpr.randn(4, 5) > 0
    A = cpr.randn(4, 5)
    B = cpr.randn(4, 5)
    check_grads(fun)(A, B)
Beispiel #6
0
def test_concatenate_axis_1_unnamed():
    """Tests whether you can specify the axis without saying "axis=1"."""
    A = cpr.randn(5, 6, 4)
    B = cpr.randn(5, 6, 4)

    def fun(x):
        return cp.concatenate((B, x, B), 1)

    check_grads(fun)(A)
Beispiel #7
0
def test_outer():
    def fun(x, y):
        return cp.outer(x, y)

    vect2 = cpr.randn(11)
    vect3 = cpr.randn(11)

    check_grads(fun)(vect2, vect3)
    check_grads(fun)(vect2.T, vect3)
    check_grads(fun)(vect2.T, vect3.T)
Beispiel #8
0
def test_r_node_and_const():
    with warnings.catch_warnings(record=True) as w:
        c = cpr.randn(3, 2)

        def fun(x):
            b = cp.r_[x, c]
            return b

        A = cpr.randn(3, 2)
        check_grads(fun)(A)
Beispiel #9
0
def test_r_slicing():
    with warnings.catch_warnings(record=True) as w:
        c = cpr.randn(10)

        def fun(x):
            b = cp.r_[x, c, 1:10]
            return b

        A = cpr.randn(10)
        check_grads(fun)(A)
Beispiel #10
0
def test_c_mixed():
    with warnings.catch_warnings(record=True) as w:
        c = cpr.randn(3, 2)

        def fun(x):
            b = cp.c_[x, c, x]
            return b

        A = cpr.randn(3, 2)
        check_grads(fun)(A)
Beispiel #11
0
def test_std_ddof():
    B = cpr.randn(3)
    C = cpr.randn(3, 4)
    D = cpr.randn(1, 3)
    combo_check(cp.std, (0, ))([B, C, D],
                               axis=[None],
                               keepdims=[True, False],
                               ddof=[0, 1])
    combo_check(cp.std, (0, ))([C, D],
                               axis=[None, 1],
                               keepdims=[True, False],
                               ddof=[2])
Beispiel #12
0
def test_dot():
    def fun(x, y):
        return cp.dot(x, y)

    mat1 = cpr.randn(10, 11)
    mat2 = cpr.randn(10, 11)
    vect1 = cpr.randn(10)
    vect2 = cpr.randn(11)
    vect3 = cpr.randn(11)

    check_grads(fun)(mat1, vect2)
    check_grads(fun)(mat1, mat2.T)
    check_grads(fun)(vect1, mat1)
    check_grads(fun)(vect2, vect3)
Beispiel #13
0
def test_squeeze_method():
    A = cpr.randn(5, 1, 4)

    def fun(x):
        return x.squeeze()

    check_grads(fun)(A)
Beispiel #14
0
def test_index_ints():
    A = cpr.randn(5, 6, 4)

    def fun(x):
        return x[3, 0, 1]

    check_grads(fun)(A)
Beispiel #15
0
def test_squeeze_func():
    A = cpr.randn(5, 1, 4)

    def fun(x):
        return cp.squeeze(x)

    check_grads(fun)(A)
Beispiel #16
0
def test_index_lists():
    A = cpr.randn(5, 6, 4).astype("float32")

    def fun(x):
        return x[[0, 1, 2], :, :]

    check_grads(fun)(A)
Beispiel #17
0
def test_index_slice():
    A = cpr.randn(5, 6, 4)

    def fun(x):
        return x[::-1, 2:4, :]

    check_grads(fun)(A)
Beispiel #18
0
def test_vector_slice():
    A = cpr.randn(5)

    def fun(x):
        return x[2:4]

    check_grads(fun)(A)
Beispiel #19
0
def test_index_mixed():
    A = cpr.randn(5, 6, 4).astype("float32")

    def fun(x):
        return x[3, 2:, [1, 3]]

    check_grads(fun)(A)
Beispiel #20
0
def test_len():
    def fun(x):
        assert len(x) == 3
        return x

    A = cpr.randn(3, 2)
    check_grads(fun)(A)
Beispiel #21
0
def test_reshape_method():
    A = cpr.randn(5, 6, 4)

    def fun(x):
        return x.reshape((5 * 4, 6))

    check_grads(fun)(A)
Beispiel #22
0
def test_reshape_call():
    A = cpr.randn(5, 6, 4)

    def fun(x):
        return cp.reshape(x, (5 * 4, 6))

    check_grads(fun)(A)
Beispiel #23
0
def test_prod_1():
    def fun(x):
        return cp.prod(x)

    mat = (cpr.randn(2, 3)**2 / 10.0 + 0.1
           )  # Gradient unstable when zeros are present.
    check_grads(fun)(mat)
Beispiel #24
0
def test_trace_extradims():
    def fun(x):
        return cp.trace(x, offset=offset)

    mat = cpr.randn(5, 6, 4, 3)
    offset = int(cpr.randint(-5, 6))
    check_grads(fun)(mat)
Beispiel #25
0
def test_ravel_method():
    A = cpr.randn(5, 6, 4)

    def fun(x):
        return x.ravel()

    check_grads(fun)(A)
Beispiel #26
0
def test_repeat_axis1_rep1():
    A = cpr.randn(5, 3, 4)

    def fun(x):
        return cp.repeat(x, 1, axis=1)

    check_grads(fun)(A)
Beispiel #27
0
def test_ravel_call():
    A = cpr.randn(5, 6, 4)

    def fun(x):
        return cp.ravel(x)

    check_grads(fun)(A)
Beispiel #28
0
def test_flatten_method():
    A = cpr.randn(5, 6, 4)

    def fun(x):
        return x.flatten()

    check_grads(fun)(A)
Beispiel #29
0
def test_repeat_axis0():
    A = cpr.randn(5, 3)

    def fun(x):
        return cp.repeat(x, 2, axis=0)

    check_grads(fun)(A)
Beispiel #30
0
def test_trace2():
    def fun(x):
        return cp.trace(x, offset=offset)

    mat = cpr.randn(11, 10)
    offset = int(cpr.randint(-9, 11))
    check_grads(fun)(mat)