示例#1
0
def test_base_connectivity():
    """Test construction of BaseConnectivity"""
    # Pairs and data shape don't match
    baseCon = _BaseConnectivity([0.5, 0.5, 0.5], [[1, 1, 2], [2, 3, 3]], 4)
    assert_array_equal(baseCon.data, [0.5, 0.5, 0.5])

    with pytest.raises(ValueError):
        baseCon = _BaseConnectivity([0.5, 0.5, 0.5], [[1, 1], [2, 3]], 3)

    # Not enough sources
    with pytest.raises(ValueError):
        baseCon = _BaseConnectivity([0.5, 0.5, 0.5], [[1, 1, 2], [2, 3, 3]], 2)

    #  Incorrecly shaped source degree
    with pytest.raises(ValueError):
        baseCon = _BaseConnectivity([0.5, 0.5, 0.5], [[1, 1, 2], [2, 3, 3]], 4,
                                    source_degree=([0, 2, 1], [0, 0, 1]))

    baseCon = _make_base_connectivity()
    assert_array_equal(baseCon.source_degree,
                       np.array([[0, 2, 2, 1, 0, 0, 0, 0, 0, 0],
                                 [0, 0, 1, 2, 2, 0, 0, 0, 0, 0]]))

    # Test properties
    assert baseCon.n_connections == 5
    state = {'data': np.array([1, 1, 1]), 'pairs': [[2, 2, 3], [3, 4, 4]],
             'n_sources': 5, 'subject': None, 'directed': False}
    baseCon.__setstate__(state)
    assert baseCon.n_sources == 5
    assert_array_equal(baseCon.source_degree[0], [0, 0, 2, 1, 0])
示例#2
0
def test_compatibility():
    """Test _iscombatible function"""
    baseCon = _make_base_connectivity()
    all_con = _make_alltoall_connectivity()
    label_con = _make_label_connectivity()

    # Test BaseConnectivity
    assert not baseCon.is_compatible(label_con)
    assert not baseCon.is_compatible(all_con)
    baseCon2 = _BaseConnectivity(np.array([6, 7, 8, 9, 10]), baseCon.pairs,
                                 baseCon.n_sources)
    assert baseCon.is_compatible(baseCon2)

    # Test VertexConnectivity
    assert not all_con.is_compatible(label_con)
    all_con2 = VertexConnectivity(np.array([4, 5, 6]), all_con.pairs,
                                  all_con.vertices)
    assert all_con.is_compatible(all_con2)

    # Test label_connectivity
    assert not label_con.is_compatible(all_con)
    label_con2 = LabelConnectivity(np.array([3, 4, 5]),
                                   pairs=label_con.pairs,
                                   labels=label_con.labels)
    assert label_con.is_compatible(label_con2)
示例#3
0
def _make_base_connectivity():
    pairs = ([1, 1, 2, 2, 3], [2, 3, 3, 4, 4])
    n_sources = 10
    data = np.arange(1, len(pairs[1]) + 1)

    return _BaseConnectivity(data, pairs, n_sources)