scipy/scipy — pull request #522 by Daniel-B-Smith (2013-04-22 13:53:32+00:00)
Title: Small optimization in LIL __getitem__ and __setitem__

At the very last moment, when __getitem__ and __setitem__ are looping through the element-wise indices, the indices are converted to lists. Benchmarks:

import scipy.sparse as sparse
import numpy as np

np.random.seed(1234)
x = sparse.rand(10000, 10000, 0.001).tolil()

Before:

%timeit x[np.arange(100), np.arange(100)]
1000 loops, best of 3: 789 us

%timeit x[np.arange(100), np.arange(100)] = 1
1000 loops, best of 3: 695 us

Now:

%timeit x[np.arange(100), np.arange(100)]
1000 loops, best of 3: 706 us

%timeit x[np.arange(100), np.arange(100)] = 1
1000 loops, best of 3: 609 us