Exemple #1
0
def test_transpose(): combo_check(np.transpose, [0],
                                  [npr.randn(2, 3, 4)],
                                  axes = [None, [0, 1, 2], [0, 2, 1],
                                                [2, 0, 1], [2, 1, 0],
                                                [1, 0, 2], [1, 2, 0]])

R = npr.randn
Exemple #2
0
def test_convolve_ignore(): combo_check(autograd.scipy.signal.convolve, [0, 1],
                                        [R(4, 3)], [R(3, 2)],
                                        axes=[([0],[0]), ([1],[1]), ([0],[1]), ([1],[0]),
                                              ([0, 1], [0, 1]), ([1, 0], [1, 0])],
                                        mode=['full', 'valid'])

def test_convolve_ignore_dot(): combo_check(autograd.scipy.signal.convolve, [0, 1],
Exemple #3
0
def test_tensordot_4(): combo_check(np.tensordot, [0, 1],
                                    [R(2, 2), R(4, 2, 2)],
                                    [R(2, 2), R(2, 2, 4)],
                                    axes=[1, 2])

# Need custom tests because gradient is undefined when arguments are identical.
def test_maximum(): combo_check(np.maximum, [0, 1],
def test_tensordot_3():
    combo_check(
        np.tensordot,
        [0, 1],
        [R(2, 3), R(2, 3, 4)],
        [R(1, 2, 3), R(2, 2, 3, 4)],
        axes=[[(0, 1), (1, 2)], [(1, 0), (2, 1)]],
    )
def test_select():
    combo_check(
        np.select,
        [1],
        [[R(3, 4, 5) > 0, R(3, 4, 5) > 0, R(3, 4, 5) > 0]],
        [[R(3, 4, 5), R(3, 4, 5), R(3, 4, 5)]],
        default=[0.0, 1.1],
    )
Exemple #6
0
def test_convolve_2d():
    combo_check(
        autograd.scipy.signal.convolve,
        [0, 1],
        [R(4, 3), R(5, 4), R(6, 7)],
        [R(2, 2), R(3, 2), R(4, 2), R(4, 1)],
        mode=["full", "valid"],
    )
Exemple #7
0
def test_convolve_ignore_dot(): combo_check(autograd.scipy.signal.convolve, [0, 1],
                                            [R(3, 3, 2)], [R(3, 2, 3)],
                                            axes=[([1],[1])],
                                            dot_axes=[([0],[2]), ([0],[0])],
                                            mode=['full', 'valid'])
### Special ###

def test_polygamma():
Exemple #8
0
def test_logsumexp5():
    combo_check(
        autograd.scipy.misc.logsumexp,
        [0],
        [R(2, 3, 4)],
        b=[np.exp(R(2, 3, 4))],
        axis=[None, 0, 1],
        keepdims=[True, False],
    )
Exemple #9
0
def test_convolve_ignore():
    combo_check(
        autograd.scipy.signal.convolve,
        [0, 1],
        [R(4, 3)],
        [R(3, 2)],
        axes=[([0], [0]), ([1], [1]), ([0], [1]), ([1], [0]), ([0, 1], [0, 1]), ([1, 0], [1, 0])],
        mode=["full", "valid"],
    )
Exemple #10
0
def test_convolve2d(): combo_check(autograd.scipy.signal.convolve2d, [0, 1],
                                   [R(4, 3), R(5, 4), R(6, 7)],
                                   [R(2, 2), R(3, 2), R(4, 3)],
                                   mode=['full', 'valid', 'same'])


### Special ###

def test_polygamma():
Exemple #11
0
def test_concatenate_3d():    combo_check(np.concatenate, [0], [(R(2, 2, 2), R(2, 2, 2))], axis=[0, 1, 2])

# def test_vstack_1d(): combo_check(np.vstack, [0], [R(2), (R(2), R(2))])
# def test_vstack_2d(): combo_check(np.vstack, [0], [R(2, 3), (R(2, 4), R(1, 4))])
# def test_vstack_3d(): combo_check(np.vstack, [0], [R(2, 3, 4), (R(2, 3, 4), R(5, 3, 4))])
# def test_hstack_2d(): combo_check(np.hstack, [0], [R(2, 3), (R(2, 4), R(1, 4))])
# def test_hstack_3d(): combo_check(np.hstack, [0], [R(2, 3, 4), (R(2, 1, 4), R(2, 5, 4))])
# def test_dstack_3d(): combo_check(np.dstack, [0], [R(2, 3, 4), (R(2, 3, 1), R(2, 3, 5))])


def test_select(): combo_check(np.select, [1], [[R(3,4,5) > 0, R(3,4,5) > 0, R(3,4,5) > 0]],
def test_cross():
    combo_check(
        np.cross,
        [0, 1],
        [R(3, 3)],
        [R(3, 3)],
        axisa=[-1, 0, 1],
        axisb=[-1, 0, 1],
        axisc=[-1, 0, 1],
        axis=[None, -1, 0, 1],
    )
Exemple #13
0
def test_concatenate_3d():    combo_check(np.concatenate, [0], [(R(2, 2, 2), R(2, 2, 2))], axis=[0, 1, 2])

# def test_vstack_1d(): combo_check(np.vstack, [0], [R(2), (R(2), R(2))])
# def test_vstack_2d(): combo_check(np.vstack, [0], [R(2, 3), (R(2, 4), R(1, 4))])
# def test_vstack_3d(): combo_check(np.vstack, [0], [R(2, 3, 4), (R(2, 3, 4), R(5, 3, 4))])
# def test_hstack_2d(): combo_check(np.hstack, [0], [R(2, 3), (R(2, 4), R(1, 4))])
# def test_hstack_3d(): combo_check(np.hstack, [0], [R(2, 3, 4), (R(2, 1, 4), R(2, 5, 4))])
# def test_dstack_3d(): combo_check(np.dstack, [0], [R(2, 3, 4), (R(2, 3, 1), R(2, 3, 5))])


#def test_select(): combo_check(np.select, [0, 1], [[R(3,4,5) > 0, R(3,4,5) > 0, R(3,4,5) > 0]],
#                                                  [[R(3,4,5),     R(3,4,5),     R(3,4,5)]], default=[0.0, 1.1])

def make_psd(mat): return np.dot(mat.T, mat) + np.eye(mat.shape[0])
def test_squeeze_method():
    combo_check(lambda x: x.squeeze(), [0], [R(5, 1, 4)])
def test_roll():
    combo_check(np.roll, [0], [R(5, 4)], [2], axis=[1, None])
def test_expand_dims():
    combo_check(np.expand_dims, [0], [R(5, 1, 3)], [2])
def test_ravel_call():
    combo_check(np.ravel, [0], [R(5, 6, 4)])
Exemple #18
0
def test_tensordot_3():
    combo_check(np.tensordot, [0, 1], [R(2, 3), R(2, 3, 4)],
                [R(1, 2, 3), R(2, 2, 3, 4)],
                axes=[[(0, 1), (1, 2)], [(1, 0), (2, 1)]])
Exemple #19
0
def test_repeat(): combo_check(np.repeat, [0], [R(2, 3, 4), R(3, 1)],
                               repeats=[0,1,2], axis = [None, 0, 1])

def test_diff():
Exemple #20
0
def test_matmul_broadcast():
    combo_check(np.matmul, [0, 1], [R(1, 2, 2)], [R(3, 2, 1)])
Exemple #21
0
def test_tensordot_2():
    combo_check(np.tensordot, [0, 1],
                [R(3), R(3, 1), R(3, 4, 2)], [R(1, 3), R(2, 3, 2)],
                axes=[[(0, ), (1, )]])
Exemple #22
0
def test_matmul():
    combo_check(np.matmul, [0, 1], [R(3), R(2, 3), R(2, 2, 3)],
                [R(3), R(3, 4), R(2, 3, 4)])
Exemple #23
0
def test_dot():
    combo_check(np.dot, [0, 1],
                [1.5, R(3), R(2, 3), R(2, 2, 3)],
                [0.3, R(3), R(3, 4), R(2, 3, 4)])
Exemple #24
0
def test_inner():
    combo_check(np.inner, [0, 1], [1.5, R(3), R(2, 3)], [0.3, R(3), R(4, 3)])
Exemple #25
0
def test_tile():
    combo_check(np.tile, [0], [R(2, 1, 3, 1)], reps=[(1, 4, 1, 2)])
    combo_check(np.tile, [0], [R(1, 2)], reps=[(1, 2), (2, 3), (3, 2, 1)])
    combo_check(np.tile, [0], [R(1)], reps=[(2, ), 2])
Exemple #26
0
def test_tensordot_4():
    combo_check(np.tensordot, [0, 1], [R(2, 2), R(4, 2, 2)],
                [R(2, 2), R(2, 2, 4)],
                axes=[1, 2])
Exemple #27
0
def test_vstack_3d(): combo_check(np.vstack, [0], [R(2, 3, 4), (R(2, 3, 4), R(5, 3, 4))])
# def test_hstack_2d(): combo_check(np.hstack, [0], [R(2, 3), (R(2, 4), R(1, 4))])
# def test_hstack_3d(): combo_check(np.hstack, [0], [R(2, 3, 4), (R(2, 1, 4), R(2, 5, 4))])
# def test_dstack_3d(): combo_check(np.dstack, [0], [R(2, 3, 4), (R(2, 3, 1), R(2, 3, 5))])

def test_select(): combo_check(np.select, [1], [[R(3,4,5) > 0, R(3,4,5) > 0, R(3,4,5) > 0]],
Exemple #28
0
def test_tensordot_5():
    combo_check(np.tensordot, [0, 1], [R(4)], [R()], axes=[0])
Exemple #29
0
def test_tile():
    combo_check(np.tile, [0], [R(2,1,3,1)], reps=[(1, 4, 1, 2)])
    combo_check(np.tile, [0], [R(1,2)], reps=[(1,2), (2,3), (3,2,1)])
    combo_check(np.tile, [0], [R(1)], reps=[(2,), 2])
Exemple #30
0
def test_repeat():
    combo_check(np.repeat, [0], [R(2, 3, 4), R(3, 1)],
                repeats=[0, 1, 2],
                axis=[None, 0, 1])
Exemple #31
0
def test_moveaxis():
    combo_check(np.moveaxis, [0], [R(2, 3, 4)],
                source=[0, 1, 2],
                destination=[0, 1, 2])
Exemple #32
0
def test_split_2d(): combo_check(np.split, [0], [R(4, 8)],    [4, [1, 2]], axis=[0, 1])
def test_split_3d(): combo_check(np.split, [0], [R(4, 4, 4)], [2, [1, 2]], axis=[0, 1, 2])
Exemple #33
0
def test_transpose():
    combo_check(np.transpose, [0], [R(2, 3, 4)],
                axes=[
                    None, [0, 1, 2], [0, 2, 1], [2, 0, 1], [2, 1, 0],
                    [1, 0, 2], [1, 2, 0]
                ])
Exemple #34
0
def test_array_split_1d(): combo_check(np.array_split, [0], [R(1), R(7)], [1, 3],      axis=[0])
def test_array_split_2d(): combo_check(np.array_split, [0], [R(7, 7)],    [4, [3, 5]], axis=[0, 1])
def test_nan_to_num():
    y = np.array([0., np.nan, np.inf, -np.inf])
    fun = lambda x: np.sum(np.sin(np.nan_to_num(x + y)))
    x = np.random.randn(4)
    combo_check(fun, [0], [x])
Exemple #36
0
def test_array_split_3d(): combo_check(np.array_split, [0], [R(7, 7, 7)], [4, [3, 5]], axis=[0, 1, 2])

def test_concatenate_1ist():  combo_check(np.concatenate, [0], [(R(1), R(3))],             axis=[0])
def test_clip():
    combo_check(np.clip, [0], [R(5, 5)], a_min=[0.1], a_max=[1.1])
Exemple #38
0
def test_concatenate_tuple(): combo_check(np.concatenate, [0], [[R(1), R(3)]],             axis=[0])
def test_concatenate_2d():    combo_check(np.concatenate, [0], [(R(2, 2), R(2, 2))],       axis=[0, 1])
def test_squeeze_call():
    combo_check(np.squeeze, [0], [R(5, 1, 4)])
Exemple #40
0
def test_concatenate_3d():    combo_check(np.concatenate, [0], [(R(2, 2, 2), R(2, 2, 2))], axis=[0, 1, 2])

def test_vstack_1d(): combo_check(np.vstack, [0], [R(2), (R(2), R(2))])
Exemple #41
0
def test_tensordot_7():
    combo_check(np.tensordot, [0, 1], [R(2, 6)], [R(6, 3)], axes=[[-1, 0]])
Exemple #42
0
def test_diff():
    combo_check(np.diff, [0], [R(5, 5), R(5, 5, 5)], n=[1, 2], axis=[0, 1])
    combo_check(np.diff, [0], [R(1), R(1, 1)], axis=[0])
    combo_check(np.diff, [0], [R(1, 1), R(3, 1)], axis=[1])
Exemple #43
0
def test_split_1d(): combo_check(np.split, [0], [R(1), R(7)], [1],         axis=[0])
def test_split_2d(): combo_check(np.split, [0], [R(4, 8)],    [4, [1, 2]], axis=[0, 1])
Exemple #44
0
def test_minimum():
    combo_check(np.minimum, [0, 1], [R(1), R(1, 4), R(3, 4)],
                [R(1), R(1, 4), R(3, 4)])
Exemple #45
0
def test_split_3d(): combo_check(np.split, [0], [R(4, 4, 4)], [2, [1, 2]], axis=[0, 1, 2])

def test_array_split_1d(): combo_check(np.array_split, [0], [R(1), R(7)], [1, 3],      axis=[0])
Exemple #46
0
def test_fmin():
    combo_check(np.fmin, [0, 1], [R(1), R(1, 4), R(3, 4)],
                [R(1), R(1, 4), R(3, 4)])
Exemple #47
0
def test_array_split_2d(): combo_check(np.array_split, [0], [R(7, 7)],    [4, [3, 5]], axis=[0, 1])
def test_array_split_3d(): combo_check(np.array_split, [0], [R(7, 7, 7)], [4, [3, 5]], axis=[0, 1, 2])
Exemple #48
0
def test_msort():
    combo_check(np.msort, [0], [R(1), R(7)])
Exemple #49
0
def test_concatenate_1ist():  combo_check(np.concatenate, [0], [(R(1), R(3))],             axis=[0])
def test_concatenate_tuple(): combo_check(np.concatenate, [0], [[R(1), R(3)]],             axis=[0])
Exemple #50
0
def test_partition():
    combo_check(np.partition, [0], [R(7), R(14)], kth=[0, 3, 6])
Exemple #51
0
def test_concatenate_2d():    combo_check(np.concatenate, [0], [(R(2, 2), R(2, 2))],       axis=[0, 1])
def test_concatenate_3d():    combo_check(np.concatenate, [0], [(R(2, 2, 2), R(2, 2, 2))], axis=[0, 1, 2])
Exemple #52
0
def test_atleast_2d():
    combo_check(
        np.atleast_2d, [0],
        [1.2, R(1), R(7), R(1, 4),
         R(2, 4), R(2, 4, 5)])
Exemple #53
0
def test_vstack_2d(): combo_check(np.vstack, [0], [R(2, 3), (R(2, 4), R(1, 4))])
def test_vstack_3d(): combo_check(np.vstack, [0], [R(2, 3, 4), (R(2, 3, 4), R(5, 3, 4))])
Exemple #54
0
def test_einsum_transpose():
    combo_check(np.einsum, [1], ['ij->ji'], [R(1, 1), R(4, 4), R(3, 4)])
Exemple #55
0
def test_transpose(): combo_check(np.transpose, [0],
                                  [R(2, 3, 4)], axes = [None, [0, 1, 2], [0, 2, 1],
                                                              [2, 0, 1], [2, 1, 0],
                                                              [1, 0, 2], [1, 2, 0]])
def test_repeat(): combo_check(np.repeat, [0], [R(2, 3, 4), R(3, 1)],
Exemple #56
0
def test_einsum_matmult():
    combo_check(np.einsum, [1, 2], ['ij,jk->ik'], [R(2, 3)], [R(3, 4)])
Exemple #57
0
def test_diff():
    combo_check(np.diff, [0], [R(5,5), R(5,5,5)], n=[1,2], axis=[0,1])
    combo_check(np.diff, [0], [R(1), R(1,1)], axis=[0])
    combo_check(np.diff, [0], [R(1,1), R(3,1)], axis=[1])
Exemple #58
0
def test_einsum_matmult_broadcast():
    combo_check(np.einsum, [1, 2], ['...ij,...jk->...ik'],
                [R(2, 3), R(2, 2, 3)], [R(3, 4), R(2, 3, 4)])
Exemple #59
0
def test_dot(): combo_check(np.dot, [0, 1],
                            [1.5, R(3), R(2, 3)],
                            [0.3, R(3), R(3, 4)])
def test_tensordot_1(): combo_check(np.tensordot, [0, 1],
def test_ravel_method():
    combo_check(lambda x: x.ravel(), [0], [R(5, 6, 4)])