# Path: patchy/helper/labeling.py
# def scanline(adjacency, labels=None):
#     with tf.name_scope('scanline', values=[adjacency, labels]):
#         return _labels_default(labels, adjacency)
# 
# def betweenness_centrality(adjacency, labels=None):
#     def _betweeness_centrality(adjacency, labels):
#         graph = nx.from_numpy_matrix(adjacency)
# 
#         labeling = nx.betweenness_centrality(graph, normalized=False)
#         labeling = list(labeling.items())
#         labeling = sorted(labeling, key=lambda n: n[1], reverse=True)
# 
#         return np.array([labels[n[0]] for n in labeling])
# 
#     labels = _labels_default(labels, adjacency)
#     return tf.py_func(_betweeness_centrality, [adjacency, labels], tf.int32,
#                       stateful=False, name='betweenness_centrality')
# 
# def canonize(adjacency, labels=None):
#     def _canonical(adjacency, labels):
#         count = adjacency.shape[0]
#         adjacency_dict = {}
# 
#         for i in xrange(count):
#             adjacency_dict[i] = list(np.nonzero(adjacency[i])[0])
# 
#         graph = nauty.Graph(count, adjacency_dict=adjacency_dict)
#         labeling = nauty.canonical_labeling(graph)
# 
#         labeling = [labels[i] for i in labeling]
# 
#         return np.array(labeling, np.int32)
# 
#     labels = _labels_default(labels, adjacency)
#     return tf.py_func(_canonical, [adjacency, labels], tf.int32,
#                       stateful=False, name='canonical')


import tensorflow as tf
from .labeling import scanline, betweenness_centrality, canonize
            [0, 1, 0, 0, 0, 1, 0],
            [0, 0, 0, 1, 1, 0, 0],
            [0, 0, 0, 1, 0, 0, 0],
        ])

        labels = tf.constant([1, 2, 3, 4, 5, 6, 7])

        expected = [4, 3, 2, 6, 5, 1, 7]

        with self.test_session() as sess:
            labeling = betweenness_centrality(adjacency, labels)
            self.assertAllEqual(labeling.eval(), expected)

    def test_canonize(self):
        adjacency = tf.constant([
            [0, 1, 1, 0, 1, 1, 0, 0],
            [1, 0, 1, 0, 0, 1, 1, 0],
            [1, 1, 0, 0, 0, 1, 0, 1],
            [0, 0, 0, 0, 0, 1, 1, 0],
            [1, 0, 0, 0, 0, 0, 0, 1],
            [1, 1, 1, 1, 0, 0, 0, 0],
            [0, 1, 0, 1, 0, 0, 0, 0],
            [0, 0, 1, 0, 1, 0, 0, 0],
        ])

        labels = tf.constant([1, 2, 3, 4, 5, 6, 7, 8])

        expected = [4, 7, 5, 8, 6, 2, 1, 3]

        with self.test_session() as sess:

# Path: patchy/helper/labeling.py
# def scanline(adjacency, labels=None):
#     with tf.name_scope('scanline', values=[adjacency, labels]):
#         return _labels_default(labels, adjacency)
# 
# def betweenness_centrality(adjacency, labels=None):
#     def _betweeness_centrality(adjacency, labels):
#         graph = nx.from_numpy_matrix(adjacency)
# 
#         labeling = nx.betweenness_centrality(graph, normalized=False)
#         labeling = list(labeling.items())
#         labeling = sorted(labeling, key=lambda n: n[1], reverse=True)
# 
#         return np.array([labels[n[0]] for n in labeling])
# 
#     labels = _labels_default(labels, adjacency)
#     return tf.py_func(_betweeness_centrality, [adjacency, labels], tf.int32,
#                       stateful=False, name='betweenness_centrality')
# 
# def canonize(adjacency, labels=None):
#     def _canonical(adjacency, labels):
#         count = adjacency.shape[0]
#         adjacency_dict = {}
# 
#         for i in xrange(count):
#             adjacency_dict[i] = list(np.nonzero(adjacency[i])[0])
# 
#         graph = nauty.Graph(count, adjacency_dict=adjacency_dict)
#         labeling = nauty.canonical_labeling(graph)
# 
#         labeling = [labels[i] for i in labeling]
# 
#         return np.array(labeling, np.int32)
# 
#     labels = _labels_default(labels, adjacency)
#     return tf.py_func(_canonical, [adjacency, labels], tf.int32,
#                       stateful=False, name='canonical')


# Path: patchy/helper/labeling_test.py
import tensorflow as tf
from .labeling import scanline, betweenness_centrality, canonize

            [0, 1, 0, 0, 0, 1, 0],
            [0, 0, 0, 1, 1, 0, 0],
            [0, 0, 0, 1, 0, 0, 0],
        ])

        labels = tf.constant([1, 2, 3, 4, 5, 6, 7])

        expected = [4, 3, 2, 6, 5, 1, 7]

        with self.test_session() as sess:
            labeling = betweenness_centrality(adjacency, labels)
            self.assertAllEqual(labeling.eval(), expected)

    def test_canonize(self):
        adjacency = tf.constant([
            [0, 1, 1, 0, 1, 1, 0, 0],
            [1, 0, 1, 0, 0, 1, 1, 0],
            [1, 1, 0, 0, 0, 1, 0, 1],
            [0, 0, 0, 0, 0, 1, 1, 0],
            [1, 0, 0, 0, 0, 0, 0, 1],
            [1, 1, 1, 1, 0, 0, 0, 0],
            [0, 1, 0, 1, 0, 0, 0, 0],
            [0, 0, 1, 0, 1, 0, 0, 0],
        ])

        labels = tf.constant([1, 2, 3, 4, 5, 6, 7, 8])

        expected = [4, 7, 5, 8, 6, 2, 1, 3]

        with self.test_session() as sess:

            labeling = canonize(adjacency, labels)