[Scipy-tickets] [SciPy] #1381: getrow generates warn 'changing the sparsity structure'

SciPy Trac scipy-tickets@scipy....
Thu Feb 3 07:16:35 CST 2011


#1381: getrow generates warn 'changing the sparsity structure'
-----------------------------------+----------------------------------------
 Reporter:  davidabarrett          |       Owner:  wnbell
     Type:  defect                 |      Status:  new   
 Priority:  normal                 |   Milestone:  0.9.0 
Component:  scipy.sparse           |     Version:  0.8.0 
 Keywords:  sparse getrow warning  |  
-----------------------------------+----------------------------------------

Old description:

> import scipy.sparse as ssp
>
> csc = ssp.csr_matrix( [ [0, 0, 13], [0, 21, 0] ])
> print 'row[0] = ', csc.getrow(0)
>
> raises exception:
> warn('changing the sparsity structure of a %s_matrix is expensive.')
>
> this is rather counterintuitive since there is no explicit structure
> being altered by this sequence.
>
> The problem is that getrow alters the resulting matrix in line 451:
>
> 445             # Spmatrix subclasses should override this method for
> efficiency.
> 446             # Pre-multiply by a (1 x m) row vector 'a' containing all
> zeros
> (Pdb)
> 447             # except for a_i = 1
> 448             from csr import csr_matrix
> 449             m = self.shape[0]
> 450             a = csr_matrix((1, m), dtype=self.dtype)
> 451             a[0, i] = 1

New description:

 {{{
 import scipy.sparse as ssp

 csc = ssp.csr_matrix( [ [0, 0, 13], [0, 21, 0] ])
 print 'row[0] = ', csc.getrow(0)
 }}}
 raises exception:
 warn('changing the sparsity structure of a %s_matrix is expensive.')

 this is rather counterintuitive since there is no explicit structure
 being altered by this sequence.

 The problem is that getrow alters the resulting matrix in line 451:
 {{{
 445             # Spmatrix subclasses should override this method for
 efficiency.
 446             # Pre-multiply by a (1 x m) row vector 'a' containing all
 zeros
 (Pdb)
 447             # except for a_i = 1
 448             from csr import csr_matrix
 449             m = self.shape[0]
 450             a = csr_matrix((1, m), dtype=self.dtype)
 451             a[0, i] = 1
 }}}

--

Comment(by warren.weckesser):

 Added code delimiters to the description.

-- 
Ticket URL: <http://projects.scipy.org/scipy/ticket/1381#comment:2>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.


More information about the Scipy-tickets mailing list