__init__.py 2.11 KB
Newer Older
Tiago Peixoto's avatar
Tiago Peixoto committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#! /usr/bin/env python
# graph_tool.py -- a general graph manipulation python module
#
# Copyright (C) 2007 Tiago de Paula Peixoto <tiago@forked.de>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

Tiago Peixoto's avatar
Tiago Peixoto committed
19
20
from .. dl_import import dl_import
dl_import("import libgraph_tool_stats")
Tiago Peixoto's avatar
Tiago Peixoto committed
21

22
from .. core import _degree, _prop
Tiago Peixoto's avatar
Tiago Peixoto committed
23
24
25
26
27
from numpy import *

__all__ = ["vertex_hist", "edge_hist", "label_components",
           "label_parallel_edges",  "label_self_loops"]

28
def vertex_hist(g, deg, bins=[1], float_count=True):
Tiago Peixoto's avatar
Tiago Peixoto committed
29
    ret = libgraph_tool_stats.\
30
          get_vertex_histogram(g._Graph__graph, _degree(g, deg), bins)
31
    return [array(ret[0], dtype="float64") if float_count else ret[0], ret[1]]
Tiago Peixoto's avatar
Tiago Peixoto committed
32

33
def edge_hist(g, eprop, bins=[1], float_count=True):
Tiago Peixoto's avatar
Tiago Peixoto committed
34
    ret = libgraph_tool_stats.\
35
          get_edge_histogram(g._Graph__graph, _prop("e", g, eprop), bins)
36
    return [array(ret[0], dtype="float64") if float_count else ret[0], ret[1]]
Tiago Peixoto's avatar
Tiago Peixoto committed
37

38
39
40
def label_components(g, vprop=None):
    if vprop == None:
        vprop = g.new_vertex_property("int32_t")
Tiago Peixoto's avatar
Tiago Peixoto committed
41
    libgraph_tool_stats.\
42
          label_components(g._Graph__graph, _prop("v", g, vprop))
43
    return vprop
Tiago Peixoto's avatar
Tiago Peixoto committed
44
45

def label_parallel_edges(g, eprop):
46
47
    if eprop == None:
        eprop = g.new_edge_property("int32_t")
Tiago Peixoto's avatar
Tiago Peixoto committed
48
    libgraph_tool_stats.\
49
          label_parallel_edges(g._Graph__graph, _prop("e", g, eprop))
50
    return eprop
Tiago Peixoto's avatar
Tiago Peixoto committed
51
52

def label_self_loops(g, eprop):
53
54
    if eprop == None:
        eprop = g.new_edge_property("int32_t")
Tiago Peixoto's avatar
Tiago Peixoto committed
55
    libgraph_tool_stats.\
56
          label_self_loops(g._Graph__graph, _prop("e", g, eprop))
57
    return eprop