forked from scipy/scipy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sparse_csgraph.py
33 lines (27 loc) · 923 Bytes
/
sparse_csgraph.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""benchmarks for the scipy.sparse.csgraph module"""
from __future__ import print_function, absolute_import
import numpy as np
import scipy.sparse
try:
from scipy.sparse.csgraph import laplacian
except ImportError:
pass
from .common import Benchmark
class Laplacian(Benchmark):
params = [
[30, 300, 900],
['dense', 'coo', 'csc', 'csr', 'dia'],
[True, False]
]
param_names = ['n', 'format', 'normed']
def setup(self, n, format, normed):
data = scipy.sparse.rand(9, n, density=0.5, random_state=42).toarray()
data = np.vstack((data, data))
diags = list(range(-9, 0)) + list(range(1, 10))
A = scipy.sparse.spdiags(data, diags, n, n)
if format == 'dense':
self.A = A.toarray()
else:
self.A = A.asformat(format)
def time_laplacian(self, n, format, normed):
laplacian(self.A, normed=normed)