import scipy.sparse

try:
    from scipy.sparse.csgraph import maximum_bipartite_matching
except ImportError:
    pass

from .common import Benchmark


class MaximumBipartiteMatching(Benchmark):
    params = [[1000, 2500], [0.01, 0.1]]
    param_names = ['n', 'density']

    def setup(self, n, density):
        graph = scipy.sparse.rand(n, n, density=density,
                                  format='csr', random_state=42)
        self.graph = graph

    def time_maximum_bipartite_matching(self, n, density):
        maximum_bipartite_matching(self.graph)

@@ -1,12 +1,31 @@
+import numpy as np%0A
 import scipy
@@ -32,16 +32,16 @@
 .sparse%0A
-
 %0Atry:%0A  
@@ -226,30 +226,49 @@
 = %5B%5B
-1
+5
 000, 
-2
+7
 500
+, 10000
 %5D, %5B0.
+00
 01, 0.
+0005, 0.00
 1%5D%5D%0A
@@ -348,120 +348,420 @@
     
-graph = scipy.sparse.rand(n, n, density=density,%0A                                  format='csr', random_state=42
+# Create random sparse matrices. Note that we could use%0A        # scipy.sparse.rand for this purpose, but simply using np.random and%0A        # disregarding duplicates is quite a bit faster.%0A        np.random.seed(42)%0A        d = np.random.randint(0, n, size=(int(n*n*density), 2))%0A        graph = scipy.sparse.csr_matrix((np.ones(len(d)), (d%5B:, 0%5D, d%5B:, 1%5D)),%0A                                        shape=(n, n)
 )%0A  

revamp setup for maximum bipartite matching benchmarks