<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/scipy/ticket/706" rel="nofollow">http://projects.scipy.org/scipy/ticket/706</a> on 2008-07-23 by trac user rjansen, assigned to <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/wnbell/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/wnbell">@wnbell</a>.</em></p>
<p dir="auto">Hi,</p>
<p dir="auto">I'm trying to compile scipy on Solaris 10:</p>
<p dir="auto">After, what seems to be a succesfull LAPACK and ATLAS build with the GNU compiler 4.0.2 (switched to sunfreeware python,w hich is build with GNU compilers<br>
and installing NumPy with same compiler, I'm bumped into the following error below when trying to compile SciPy.</p>
<p dir="auto">This same error shows also when using the Sun Studio 12 compiler chain. (everything rebuild with Sun compilers, due to the python used from the blastwave.org packages)</p>
<p dir="auto">The SciPy build stage seems to switch/default to Sun Studio compiler again</p>
<p dir="auto">scipy/optimize/minpack2/dcstep.f:<br>
dcstep:<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 2602: Warning: String literal converted to char* in initialization.<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 2603: Warning: String literal converted to char* in initialization.<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 2604: Warning: String literal converted to char* in initialization.<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 2605: Warning: String literal converted to char* in initialization.<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 2606: Warning: String literal converted to char* in initialization.<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 2607: Warning: String literal converted to char* in initialization.<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 2608: Warning: String literal converted to char* in initialization.<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 2609: Warning: String literal converted to char* in initialization.<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 2610: Warning: String literal converted to char* in initialization.<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 2611: Warning: String literal converted to char* in initialization.<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 2612: Warning: String literal converted to char* in initialization.<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 2614: Warning: String literal converted to char* in initialization.<br>
"scipy/sparse/sparsetools/sparsetools.h", line 409: Error: multiplies is not a member of std.<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 15087:     Where: While instantiating "csr_elmul_csr&lt;int, int&gt;(const int, const int, const int_, const int_, const int_, const int_, const int_, const int_, std::vector<em>, std::vector</em>, std::vector<em>)".<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 15087:     Where: Instantiated from non-template code.<br>
"scipy/sparse/sparsetools/sparsetools.h", line 409: Error: Unexpected type name "T" encountered.<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 15087:     Where: While instantiating "csr_elmul_csr&lt;int, int&gt;(const int, const int, const int</em>, const int_, const int_, const int_, const int_, const int_, std::vector<em>, std::vector</em>, std::vector<em>)".<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 15087:     Where: Instantiated from non-template code.<br>
"scipy/sparse/sparsetools/sparsetools.h", line 409: Error: Operand expected instead of ")".<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 15087:     Where: While instantiating "csr_elmul_csr&lt;int, int&gt;(const int, const int, const int</em>, const int_, const int_, const int_, const int_, const int_, std::vector<em>, std::vector</em>, std::vector<em>)".<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 15087:     Where: Instantiated from non-template code.<br>
3 Error(s) and 12 Warning(s) detected.<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 2602: Warning: String literal converted to char</em> in initialization.<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 2603: Warning: String literal converted to char* in initialization.<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 2604: Warning: String literal converted to char* in initialization.<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 2605: Warning: String literal converted to char* in initialization.<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 2606: Warning: String literal converted to char* in initialization.<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 2607: Warning: String literal converted to char* in initialization.<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 2608: Warning: String literal converted to char* in initialization.<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 2609: Warning: String literal converted to char* in initialization.<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 2610: Warning: String literal converted to char* in initialization.<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 2611: Warning: String literal converted to char* in initialization.<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 2612: Warning: String literal converted to char* in initialization.<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 2614: Warning: String literal converted to char* in initialization.<br>
"scipy/sparse/sparsetools/sparsetools.h", line 409: Error: multiplies is not a member of std.<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 15087:     Where: While instantiating "csr_elmul_csr&lt;int, int&gt;(const int, const int, const int_, const int_, const int_, const int_, const int_, const int_, std::vector<em>, std::vector</em>, std::vector<em>)".<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 15087:     Where: Instantiated from non-template code.<br>
"scipy/sparse/sparsetools/sparsetools.h", line 409: Error: Unexpected type name "T" encountered.<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 15087:     Where: While instantiating "csr_elmul_csr&lt;int, int&gt;(const int, const int, const int</em>, const int_, const int_, const int_, const int_, const int_, std::vector<em>, std::vector</em>, std::vector<em>)".<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 15087:     Where: Instantiated from non-template code.<br>
"scipy/sparse/sparsetools/sparsetools.h", line 409: Error: Operand expected instead of ")".<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 15087:     Where: While instantiating "csr_elmul_csr&lt;int, int&gt;(const int, const int, const int</em>, const int_, const int_, const int_, const int_, const int_, std::vector<em>, std::vector</em>, std::vector*)".<br>
"scipy/sparse/sparsetools/sparsetools_wrap.cxx", line 15087:     Where: Instantiated from non-template code.<br>
3 Error(s) and 12 Warning(s) detected.<br>
error: Setup script exited with error: Command "CC -DNDEBUG -xO3 -xtarget=ultra -xarch=v8 -Iscipy/sparse/sparsetools -I/opt/csw/lib/python/site-packages/numpy-1.1.0-py2.5-solaris-2.10-sun4u.egg/numpy/core/include -I/opt/csw/include/python2.5 -c scipy/sparse/sparsetools/sparsetools_wrap.cxx -o build/temp.solaris-2.10-sun4u-2.5/scipy/sparse/sparsetools/sparsetools_wrap.o" failed with exit status 3</p>
<p dir="auto">This started out as a <a href="http://stackoverflow.com/a/42349847/7207392" rel="nofollow">hack</a> on stack overflow to speed up construction of csr matrices.</p>
<p dir="auto">As in some cases savings are considerable (several-fold reduction in time needed), it was suggested to me to offer this for inclusion in scipy.</p>
<p dir="auto">I'm on Python 3.6, numpy 1.11.3, scipy 0.18.1</p>
<p dir="auto">The speedup is achieved by</p>
<ul dir="auto">
<li>using int32 and viewcasting this to int64 in the indirect sort of indices</li>
<li>using quicksort instead of mergesort since duplicate indices are fused anyway (is there any deeper reason lexsort doesn't let you pick the sort algo?)</li>
<li>using argsort instead of lexsort</li>
</ul>
<p dir="auto">I attach a proof-of-concept version lacking checks for endianness and index size.</p>
<p dir="auto">Nico Schlömer has offered to add some timings.</p>
<p dir="auto"><a href="https://github.com/scipy/scipy/files/790580/fast_tocsr.py.txt">fast_tocsr.py.txt</a></p>