Пример #1
0
def test_diag_indices():
    di = diag_indices(4)
    a = np.array([[1, 2, 3, 4],
                  [5, 6, 7, 8],
                  [9, 10, 11, 12],
                  [13, 14, 15, 16]])
    a[di] = 100
    assert_array_equal(
        a, np.array([[100, 2, 3, 4],
                     [5, 100, 7, 8],
                     [9, 10, 100, 12],
                     [13, 14, 15, 100]])
        )

    # Now, we create indices to manipulate a 3-d array:
    d3 = diag_indices(2, 3)

    # And use it to set the diagonal of a zeros array to 1:
    a = np.zeros((2, 2, 2), int)
    a[d3] = 1
    assert_array_equal(
        a, np.array([[[1, 0],
                      [0, 0]],
                     [[0, 0],
                      [0, 1]]])
        )
Пример #2
0
def test_diag_indices():
    di = diag_indices(4)
    a = np.array([[1, 2, 3, 4],
                  [5, 6, 7, 8],
                  [9, 10, 11, 12],
                  [13, 14, 15, 16]])
    a[di] = 100
    assert_array_equal(
        a, np.array([[100, 2, 3, 4],
                     [5, 100, 7, 8],
                     [9, 10, 100, 12],
                     [13, 14, 15, 100]])
        )

    # Now, we create indices to manipulate a 3-d array:
    d3 = diag_indices(2, 3)

    # And use it to set the diagonal of a zeros array to 1:
    a = np.zeros((2, 2, 2), int)
    a[d3] = 1
    assert_array_equal(
        a, np.array([[[1, 0],
                      [0, 0]],
                     [[0, 0],
                      [0, 1]]])
        )
Пример #3
0
def test_mesh_laplacian():
    td = get_testdir()
    s = Surface(op.join(td, 'in.surf.gii'))

    try:
        s.mesh_laplacian(-1)
    except Exception as e:
        assert isinstance(
            e, ValueError), 'negative distance weight should give ValueError'

    for w in range(4):
        lap = s.mesh_laplacian(distance_weight=w)
        assert (lap[np.diag_indices(lap.shape[0])] <
                0).min(), 'positive diagonal'

    outs = Surface(op.join(td, 'out.surf.gii'))
    spc = toblerone.ImageSpace(op.join(td, 'ref.nii.gz'))
    hemi = toblerone.Hemisphere(s, outs, 'L')
    hemi2 = toblerone.Hemisphere(s, outs, 'R')
    proj = toblerone.projection.Projector([hemi, hemi2], spc)

    for w in range(4):
        lap = proj.mesh_laplacian(w)
        n = proj.hemi_dict['L'].n_points
        assert not slice_sparse(lap, slice(0, n), slice(n, 2 * n)).nnz
        assert not slice_sparse(lap, slice(n, 2 * n), slice(0, n)).nnz
        assert not (lap[diag_indices(2 * n)] > 0).any()