scipy/scipy — pull request #512 by WarrenWeckesser (2013-04-16 16:48:24+00:00)
Title: BUG: sparse: coo_matrix.todia() would fail when the matrix was all zeros.

This PR fixes a bug in coo_matrix.todia(). The method raises an exception if the array is all zeros. For example:

In [3]: from scipy.sparse import coo_matrix

In [4]: z = [[0, 0]]

In [5]: c = coo_matrix(z)

In [6]: d = c.todia()
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
in ()
----> 1 d = c.todia()

/home/warren/anaconda/lib/python2.7/site-packages/scipy/sparse/coo.pyc in todia(self)
336
337 #initialize and fill in data array
--> 338 data = np.zeros( (len(diags), self.col.max()+1), dtype=self.dtype)
339 data[ np.searchsorted(diags,ks), self.col ] = self.data
340

/home/warren/anaconda/lib/python2.7/site-packages/numpy/core/_methods.pyc in _amax(a, axis, out, keepdims)
8 def _amax(a, axis=None, out=None, keepdims=False):
9 return um.maximum.reduce(a, axis=axis,
---> 10 out=out, keepdims=keepdims)
11
12 def _amin(a, axis=None, out=None, keepdims=False):

ValueError: zero-size array to reduction operation maximum which has no identity