[Scipy-tickets] [SciPy] #1582: APPCRASH error when trying to use Latent Semantic Indexing method with Gensim

SciPy Trac scipy-tickets@scipy....
Sun Jan 22 09:44:27 CST 2012

#1582: APPCRASH error when trying to use Latent Semantic Indexing method with
  Reporter:  Shahab   |       Owner:  somebody
      Type:  defect   |      Status:  closed  
  Priority:  high     |   Milestone:  0.11.0  
 Component:  Other    |     Version:  0.10.0  
Resolution:  invalid  |    Keywords:          

Comment(by warren.weckesser):

 For completeness, here's a script that does not involve gensim that can
 cause a seg. fault.  The problem is that neither the constructor
 csc_matrix() nor the function csc_matvecs() does any error checking, and
 csc_matvecs() is just a wrapper of C++ code, so incorrect values can
 easily result in memory corruption.
 import numpy as np

 from scipy.sparse import csc_matrix
 from scipy.sparse.sparsetools import csc_matvecs

 # A diagonal CSC matrix.
 data = np.array([1.0, 2.0, 3.0])
 indices = np.array([0, 1, 2])
 indptr = np.array([0,1,2,3])

 a = csc_matrix((data, indices, indptr), shape=(3,3))

 print a.todense()

 x = np.array([10.0, 20.0, 30.0])
 y = np.array([0.0, 0.0, 0.0])
 print "before: y =", y
 # Compute y += a * x (matrix mult)
 csc_matvecs(3, 3, 1, a.indptr, a.indices, a.data, x, y)
 print "after:  y =", y

 bad_indices = np.array([100, 1, 2])  # 100 is an invalid index.

 bad = csc_matrix((data, bad_indices, indptr), shape=(3,3))

     print bad.todense()
 except ValueError as exc:
     print "*** ValueError(%r)" % exc.args[0]

 print "before: y =", y
 # Try to compute y += bad * x (matrix mult)
 # This will (probably) cause a seg. fault or some other problem.
 csc_matvecs(3, 3, 1, bad.indptr, bad.indices, bad.data, x, y)
 print "after:  y =", y

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

More information about the Scipy-tickets mailing list