

def test_make_diagonal():

    def fun(D):
        return to_scalar(np.make_diagonal(D, axis1=(- 1), axis2=(- 2)))
    D = np.random.randn(4)
    A = np.make_diagonal(D, axis1=(- 1), axis2=(- 2))
    assert np.allclose(np.diag(A), D)
    check_grads(fun, D)
    D = np.random.randn(3, 4)
    A = np.make_diagonal(D, axis1=(- 1), axis2=(- 2))
    assert all([np.allclose(np.diag(A[i]), D[i]) for i in range(3)])
    check_grads(fun, D)

dataset/ETHPy150Open HIPS/autograd/tests/test_numpy.py test_make_diagonal/original