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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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])
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)
def test_squeeze_method(): A = cpr.randn(5, 1, 4) def fun(x): return x.squeeze() check_grads(fun)(A)
def test_index_ints(): A = cpr.randn(5, 6, 4) def fun(x): return x[3, 0, 1] check_grads(fun)(A)
def test_squeeze_func(): A = cpr.randn(5, 1, 4) def fun(x): return cp.squeeze(x) check_grads(fun)(A)
def test_index_lists(): A = cpr.randn(5, 6, 4).astype("float32") def fun(x): return x[[0, 1, 2], :, :] check_grads(fun)(A)
def test_index_slice(): A = cpr.randn(5, 6, 4) def fun(x): return x[::-1, 2:4, :] check_grads(fun)(A)
def test_vector_slice(): A = cpr.randn(5) def fun(x): return x[2:4] check_grads(fun)(A)
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)
def test_len(): def fun(x): assert len(x) == 3 return x A = cpr.randn(3, 2) check_grads(fun)(A)
def test_reshape_method(): A = cpr.randn(5, 6, 4) def fun(x): return x.reshape((5 * 4, 6)) check_grads(fun)(A)
def test_reshape_call(): A = cpr.randn(5, 6, 4) def fun(x): return cp.reshape(x, (5 * 4, 6)) check_grads(fun)(A)
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)
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)
def test_ravel_method(): A = cpr.randn(5, 6, 4) def fun(x): return x.ravel() check_grads(fun)(A)
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)
def test_ravel_call(): A = cpr.randn(5, 6, 4) def fun(x): return cp.ravel(x) check_grads(fun)(A)
def test_flatten_method(): A = cpr.randn(5, 6, 4) def fun(x): return x.flatten() check_grads(fun)(A)
def test_repeat_axis0(): A = cpr.randn(5, 3) def fun(x): return cp.repeat(x, 2, axis=0) check_grads(fun)(A)
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)