This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
########################################################### | |
#### Summary All Tests: | |
(('()', 6, False), <class 'numpy.int32'>): 9920 | |
(('()', 4, False), <class 'numpy.int32'>): 8393 | |
(('(array([0, 0, 1, 1, 2, 3], dtype=int32), array([4, 5, 0, 1, 1, 0], dtype=int32))', 6, False), <class 'numpy.int32'>): 3654 | |
(('()', 5, False), <class 'numpy.int32'>): 3441 | |
(('()', 3, False), <class 'numpy.int32'>): 3402 | |
(('(array([1, 2, 0, 1, 2, 0, 1, 2], dtype=int32), array([0, 2, 5, 8], dtype=int32))', 3, True), <class 'numpy.int32'>): 3247 | |
(('(array([0, 3, 0, 2, 1], dtype=int32), array([0, 2, 4, 5], dtype=int32))', 4, True), <class 'numpy.int32'>): 3129 | |
(('(array([0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2], dtype=int32), array([0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3], dtype=int32))', 4, False), <class 'numpy.int32'>): 2791 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See the bottom for demo lines that print desired output | |
# | |
# key idea: store the nD array as a 2D array by raveling | |
# some axes into the rows and some axes into the columns. | |
# | |
# element-wise operations work nicely with the 2D version of the array | |
# and can be converted back to nD when needed. | |
# | |
# Two important functions here are `get_2d_coords` and `get_nd_coords` | |
# which convert between nD and 2D coords. The data elements stay in the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from timeit import Timer | |
# This is gratefully modeled after the benchmarks found in | |
# the numpy svn repository. http://svn.scipy.org/svn/numpy/trunk | |
import networkx as nx | |
class Benchmark(object): | |
""" | |
Benchmark a method or simple bit of code using different Graph classes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
class NodesView(object): | |
def __init__(self, graph, data=False, default=None): | |
self.G = graph | |
self.data = data | |
self.default = default | |
def __iter__(self): | |
data=self.data | |
if data is True: |