Exemplo n.º 1
0
    for c in classes:
        idxs = np.flatnonzero(y == c)
        idxs = RNG(seed=1337).choice(idxs, samples_per_class, replace=False)
        for i, idx in enumerate(idxs):
            plt_idx = i * num_classes + c + 1
            ax = plt.subplot(samples_per_class, num_classes, plt_idx)
            ax.spines['bottom'].set_linewidth(2.)
            ax.spines['top'].set_linewidth(2.)
            ax.spines['left'].set_linewidth(2.)
            ax.spines['right'].set_linewidth(2.)
            plt.tick_params(axis='both',
                            which='both',
                            bottom='off',
                            top='off',
                            left='off',
                            right='off',
                            labelbottom='off',
                            labelleft='off',
                            labelright='off')
            plt.imshow(X[idx].astype('uint8'), **imshow_params)
            if i == 0:
                plt.title(get_cifar10_label(c))
    plt.suptitle(title, **title_params)
    plt.subplots_adjust(wspace=0, hspace=0)


if __name__ == '__main__':
    # run corresponding tests
    from testing import run_tests
    run_tests(__file__)
Exemplo n.º 2
0
    lambda: sssp_test(bellman_ford,
                      with_weight_w(nx.circular_ladder_graph(4), 2.0), 0),  # 9
    lambda: sssp_test(bellman_ford,
                      with_weight_w(nx.circular_ladder_graph(6), 2.0), 0
                      ),  # 10
    lambda: sssp_test(bellman_ford, G_negative_edges, 0),  # 11
    lambda: sssp_test(dial, with_weight_w(nx.path_graph(10)), 0),  # 12
    lambda: sssp_test(dial, with_weight_w(nx.star_graph(10), 2.0), 0),  # 13
    lambda: sssp_test(dial, with_weight_w(nx.complete_graph(10)), 0),  # 14
    lambda: sssp_test(dial, with_weight_w(nx.circular_ladder_graph(20), 2.0), 0
                      ),  # 15
    lambda: sssp_test(dial, G_spt_different_weights, 0),  # 16
    lambda: sssp_test(delta_stepping, with_weight_w(nx.path_graph(10)), 0
                      ),  # 17
    lambda: sssp_test(delta_stepping, with_weight_w(nx.star_graph(10), 2.0), 0
                      ),  # 18
    lambda: sssp_test(delta_stepping, with_weight_w(nx.complete_graph(10)), 0
                      ),  # 19
    lambda: sssp_test(delta_stepping,
                      with_weight_w(nx.circular_ladder_graph(20), 2.0), 0
                      ),  # 20
    lambda: sssp_test(delta_stepping, G_spt_different_weights, 0),  # 21
    lambda: sssp_test(delta_stepping, G_disconnected_graph, 0),  # 22
    lambda: sssp_test(dial, G_disconnected_graph, 0),  # 23
    lambda: sssp_test(bellman_ford, G_disconnected_graph, 0),  # 24
    lambda: sssp_test(dijkstra, G_disconnected_graph, 0),  # 25
]

if __name__ == "__main__":
    run_tests(tests)
Exemplo n.º 3
0
        while remaining != '':
            doc = remaining[:50]
            remaining = remaining[50:]
            to_send.append(doc)
        while to_send:
            docpart = to_send.popleft()
            b_complete = 0
            if not to_send:
                b_complete = 1
            #
            payload = gruel_press.create_docdata_payload(b_complete=b_complete,
                                                         data=docpart)
            #
            cs_tcp_recv = cs.CsTcpRecv()
            cs_tcp_recv.engine = engine
            cs_tcp_recv.client_sid = 'fake_sid'
            cs_tcp_recv.data = payload
            prop_gruel_client._engine_on_tcp_recv(cs_tcp_recv=cs_tcp_recv)

    server_sends_large_doc()
    #
    # confirm effects
    assert len(doc_receiver.docs) > docs_received
    assert doc_receiver.docs[-1] == large_doc
    #
    return True


if __name__ == '__main__':
    run_tests(unders_file=sys.modules['__main__'].__file__)
Exemplo n.º 4
0
    spt_actual = impl(G)

    # all vertices in SPT
    vertices_present_msg = {True: "all_present", False: "vertex_missing"}
    vp_test_result = (len(spt_actual.nodes()) == len(G.nodes())) and (set(spt_actual.nodes()) == set(G.nodes()))

    # summary cost equal to one returned by NetworkX
    cost_equal_msg = {True: "cost_equal", False: "cost_different"}
    calc_cost = lambda G: reduce(lambda a,b: a+b, map(lambda (u, v): G[u][v]["weight"], G.edges()))
    ce_test_result = calc_cost(spt_actual) == calc_cost(nx.minimum_spanning_tree(G))

    # edges in SPT should be subset of edges in G
    edges_subset_msg = {True: "edge_subset", False: "additional_edges"}
    edges_without_data = lambda G: map(lambda t: t[0:2], G.edges())
    # this is needed because for undirected graphs NetworkX has edges only in one direction
    edges_without_data_G = edges_without_data(G)
    edges_both_dirs_G = edges_without_data_G + map(lambda t: tuple(reversed(t)), edges_without_data_G)
    es_test_result = set(edges_without_data(spt_actual)) <= set(edges_both_dirs_G)

    result_str_repr = lambda vp, ce, es: vertices_present_msg[vp] + "_" + cost_equal_msg[ce] + "_" + edges_subset_msg[es]

    return result_str_repr(vp_test_result, ce_test_result, es_test_result), result_str_repr(True, True, True)

tests = [
    lambda: spt_func_test(kruscal, with_weight_w(nx.complete_graph(10), 2.0)),
    lambda: spt_func_test(kruscal, G_spt_different_weights),
]

if __name__ == "__main__":
    run_tests(tests)
Exemplo n.º 5
0
    def run_from_argv(self, argv):
        import nose2

        with run_tests():
            nose2.main(module=None, argv=argv[1:])
Exemplo n.º 6
0
    def run_from_argv(self, argv):
        import nose

        with run_tests():
            nose.main(argv[2:])
Exemplo n.º 7
0
    def run_from_argv(self, argv):
        import pytest

        with run_tests():
            pytest.main(argv[2:])