def unary_ufunc_check(fun, lims=[-2, 2], test_complex=True, **kwargs): scalar = transform(lims, 0.4) vector = transform(lims, npr.rand(2)) mat = transform(lims, npr.rand(3, 2)) mat2 = transform(lims, npr.rand(1, 2)) check = combo_check(fun, (0,), **kwargs) check([scalar, vector, mat, mat2]) if test_complex: comp = transform(lims, 0.4) + 0.1j * transform(lims, 0.3) matc = transform(lims, npr.rand(3, 2)) + 0.1j * npr.rand(3, 2) check([comp, matc])
def binary_ufunc_check(fun, lims_A=[-2, 2], lims_B=[-2, 2], test_complex=True, **kwargs): T_A = lambda x : transform(lims_A, x) T_B = lambda x : transform(lims_B, x) scalar = 0.6 vector = npr.rand(2) mat = npr.rand(3, 2) mat2 = npr.rand(1, 2) check = combo_check(fun, (0, 1), **kwargs) check([T_A(scalar), T_A(vector), T_A(mat), T_A(mat2)], [T_B(scalar), T_B(vector), T_B(mat), T_B(mat2)]) if test_complex: comp = 0.6 + 0.3j matc = npr.rand(3, 2) + 0.1j * npr.rand(3, 2) check([T_A(scalar), T_A(comp), T_A(vector), T_A(matc), T_A(mat2)], [T_B(scalar), T_B(comp), T_B(vector), T_B(matc), T_B(mat2)])
def stat_check(fun, test_complex=True, **kwargs): # Tests functions that compute statistics, like sum, mean, etc x = 3.5 A = npr.randn() B = npr.randn(3) C = npr.randn(2, 3) D = npr.randn(1, 3) check = combo_check(fun, (0,), **kwargs) check([x, A]) check([B, C, D], axis=[None, 0], keepdims=[True, False]) check([C, D], axis=[None, 0, 1], keepdims=[True, False]) if test_complex: c = npr.randn() + 0.1j*npr.randn() E = npr.randn(2,3) + 0.1j*npr.randn(2,3) check([x, c, A]) check([B, C, D, E], axis=[None, 0], keepdims=[True, False])
def binary_ufunc_check_no_same_args(fun, lims_A=[-2, 2], lims_B=[-2, 2], test_complex=True, **kwargs): T_A = lambda x : transform(lims_A, x) T_B = lambda x : transform(lims_B, x) scalar1 = 0.6; scalar2 = 0.7 vector1 = npr.rand(2); vector2 = npr.rand(2) mat11 = npr.rand(3, 2); mat12 = npr.rand(3, 2) mat21 = npr.rand(1, 2); mat22 = npr.rand(1, 2) check = combo_check(fun, (0, 1), **kwargs) check([T_A(scalar1), T_A(vector1), T_A(mat11), T_A(mat21)], [T_B(scalar2), T_B(vector2), T_B(mat12), T_B(mat22)]) if test_complex: comp1 = 0.6 + 0.3j; comp2 = 0.1 + 0.2j matc1 = npr.rand(3, 2) + 0.1j * npr.rand(3, 2) matc2 = npr.rand(3, 2) + 0.1j * npr.rand(3, 2) check([T_A(scalar1), T_A(comp1), T_A(vector1), T_A(matc1), T_A(mat21)], [T_B(scalar2), T_B(comp2), T_B(vector2), T_B(matc2), T_B(mat22)])
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])
def test_t_pdf_broadcast(): combo_check(stats.t.pdf, [0, 1, 2, 3])([R(4, 3)], [R(1, 3)**2 + 2.1], [R(4, 3)], [R(4, 1)**2 + 2.1])
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])
def test_column_stack_2d(): combo_check(np.column_stack, [0])([R(2, 2), (R(2, 2), R(2, 2))]) 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_hstack_3d(): combo_check(np.hstack, [0])([R(2, 3, 4), (R(2, 1, 4), R(2, 5, 4))]) def test_stack_1d(): combo_check(np.stack, [0])([(R(2),), (R(2), R(2))], axis=[0, 1])
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_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])
def test_dirichlet_logpdf_x(): combo_check(normalized_dirichlet_logpdf, [0])([x], [alpha])
def test_mvn_logpdf_broadcast(): combo_check(symmetrize_matrix_arg(mvn.logpdf, 2), [0, 1, 2], [R(5, 4)], [R(4)], [make_psd(R(4, 4))])
def test_mvn_logpdf_sing_cov(): combo_check(mvn.logpdf, [0, 1])([np.concatenate( (R(2), np.zeros(2)))], [np.concatenate((R(2), np.zeros(2)))], [C], [True])
def test_mvn_entropy(): combo_check(mvn.entropy, [0, 1], [R(4)], [make_psd(R(4, 4))])
def test_mvn_logpdf(): combo_check(symmetrize_matrix_arg(mvn.logpdf, 2), [0, 1, 2], [R(4)], [R(4)], [make_psd(R(4, 4))], allow_singular=[False])
def test_t_logcdf_broadcast(): combo_check(stats.t.logcdf, [0, 2])([R(4, 3)], [R(1, 3)**2 + 2.1], [R(4, 3)], [R(4, 1)**2 + 2.1])
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])
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])
def test_dirichlet_logpdf_alpha(): combo_check(stats.dirichlet.logpdf, [1])([x], [alpha])
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])
def test_logsumexp1(): combo_check(autograd.scipy.misc.logsumexp, [0], modes=['fwd', 'rev'])([1.1, R(4), R(3, 4)], axis=[None, 0], keepdims=[True, False])
def test_hstack_1d(): combo_check(np.hstack, [0])([R(2), (R(2), R(2))]) def test_hstack_2d(): combo_check(np.hstack, [0])([R(3, 2), (R(3, 4), R(3, 5))])
def test_logsumexp2(): combo_check(autograd.scipy.misc.logsumexp, [0], modes=['fwd', 'rev'])( [R(3, 4), R(4, 5, 6), R(1, 5)], axis=[None, 0, 1], keepdims=[True, False])
def test_row_stack_2d(): combo_check(np.row_stack, [0])([R(2, 3), (R(2, 4), R(1, 4))]) def test_column_stack_1d(): combo_check(np.column_stack, [0])([R(2), (R(2), R(2))])
def test_logsumexp5(): combo_check(autograd.scipy.misc.logsumexp, [0], modes=['fwd', 'rev'])([R(2, 3, 4)], b=[np.exp(R(2, 3, 4))], axis=[None, 0, 1], keepdims=[True, False])
def test_moveaxis(): combo_check(np.moveaxis, [0])( [R(2, 3, 4)], source=[0, 1, 2], destination=[0, 1, 2]) def test_repeat(): combo_check(np.repeat, [0])([R(2, 3, 4), R(3, 1)],
def test_convolve(): combo_check(autograd.scipy.signal.convolve, [0, 1])([R(4), R(5), R(6)], [R(2), R(3), R(4)], mode=['full', 'valid'])
def test_t_logpdf(): combo_check(stats.t.logpdf, [0, 1, 2, 3])([R(4)], [R(4)**2 + 2.1], [R(4)], [R(4)**2 + 2.1])
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'])
def test_dsplit_3d(): combo_check(np.dsplit, [0])([R(4, 4, 4)], [2, [1, 2]]) def test_split_1d(): combo_check(np.split, [0])([R(1), R(7)], [1], axis=[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'])
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])
def test_betainc(): combo_check(special.betainc, [2])([R(4)**2 + 1.1], [R(4)**2 + 1.1], [U(0., 1., 4)])
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_betaln(): combo_check(special.betaln, [0, 1])([R(4)**2 + 1.1], [R(4)**2 + 1.1])
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_gammaincc(): combo_check(special.gammaincc, [1])([1], R(4)**2 + 1.3)
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_polygamma(): combo_check(special.polygamma, [1])([0], R(4)**2 + 1.3)
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_yn(): combo_check(special.yn, [1])([2], R(4)**2 + 1.3)
def test_vstack_3d(): combo_check(np.vstack, [0])([R(2, 3, 4), (R(2, 3, 4), R(5, 3, 4))]) def test_hstack_1d(): combo_check(np.hstack, [0])([R(2), (R(2), R(2))])
def test_multigammaln(): combo_check(special.multigammaln, [0])([U(4., 5.), U(4., 5., (2, 3))], [1, 2, 3])
def test_hstack_2d(): combo_check(np.hstack, [0])([R(3, 2), (R(3, 4), R(3, 5))]) def test_hstack_3d(): combo_check(np.hstack, [0])([R(2, 3, 4), (R(2, 1, 4), R(2, 5, 4))])
def test_odeint(): combo_check(integrate.odeint, [1, 2, 3])([func], [R(3)], [np.linspace(0.1, 0.2, 4)], [(R(3), R(3))])
def test_stack_1d(): combo_check(np.stack, [0])([(R(2),), (R(2), R(2))], axis=[0, 1]) def test_row_stack_1d(): combo_check(np.row_stack, [0])([R(2), (R(2), R(2))])
def test_chi2_logpdf(): combo_check(stats.chi2.logpdf, [0])([R(4)**2 + 1.1], [1, 2, 3])
def test_column_stack_1d(): combo_check(np.column_stack, [0])([R(2), (R(2), R(2))]) def test_column_stack_2d(): combo_check(np.column_stack, [0])([R(2, 2), (R(2, 2), R(2, 2))])
def test_beta_cdf(): combo_check(stats.beta.cdf, [0])([U(0., 1., 4)], [R(4)**2 + 1.1], [R(4)**2 + 1.1])
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_moveaxis(): combo_check(np.moveaxis, [0])(
def test_beta_logpdf(): combo_check(stats.beta.logpdf, [0, 1, 2])([U(0., 1., 4)], [R(4)**2 + 1.1], [R(4)**2 + 1.1])
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():
def test_gamma_cdf(): combo_check(stats.gamma.cdf, [0])([R(4)**2 + 1.1], [R(4)**2 + 1.1])
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])
def test_poisson_pmf_broadcast(): combo_check(stats.poisson.pmf, [1])([np.round(R(4, 3)**2)], [R(4, 1)**2 + 1.1])
def test_gamma_pdf(): combo_check(stats.gamma.pdf, [0, 1])([R(4)**2 + 1.1], [R(4)**2 + 1.1])
def test_t_logcdf(): combo_check(stats.t.logcdf, [0, 2])([R(4)], [R(4)**2 + 2.1], [R(4)], [R(4)**2 + 2.1])
def test_hsplit_3d(): combo_check(np.hsplit, [0])([R(4, 4, 4)], [2, [1, 2]]) def test_dsplit_3d(): combo_check(np.dsplit, [0])([R(4, 4, 4)], [2, [1, 2]])
def test_poisson_pmf(): combo_check(stats.poisson.pmf, [1])([np.round(R(4)**2)], [R(4)**2 + 1.1])