scipy/scipy — pull request #3440 by pv (2014-03-08 19:19:54+00:00)
Title: MAINT: wrap sparsetools manually instead via SWIG

This PR changes sparsetools to be wrapped via custom code generation rather than via SWIG.

This reduces memory and time requirements for compiling sparsetools. The approach is scalable: the set of routines can be easily split into smaller compilation units if necessary. Code generation is done at build time, so there are also no huge autogenerated files checked in the VCS.

I also took a look at Cython: fused types don't seem to play together with C++ templates at the moment. A similar code generation framework and `call_thunk` would be then needed also with Cython, and I think the present approach is less magical.

Some statistics:
```
#
# Before (master @ 7c64f1969)
#
$ /usr/bin/time -v g++ -Wall -D__STDC_FORMAT_MACROS -O3 -c -o /dev/null -Isparsetools -I/usr/include/python2.7 sparsetools/bsr_wrap.cxx
Elapsed (wall clock) time (h:mm:ss or m:ss): 1:49.53
Maximum resident set size (kbytes): 1140424

$ /usr/bin/time -v g++ -Wall -D__STDC_FORMAT_MACROS -O3 -c -o /dev/null -Isparsetools -I/usr/include/python2.7 sparsetools/csr_wrap.cxx
Elapsed (wall clock) time (h:mm:ss or m:ss): 1:14.86
Maximum resident set size (kbytes): 1089156

$ sloccount sparsetools (counting autogenerated files, too)
Total Physical Source Lines of Code (SLOC) = 440,250

#
# After
#
$ /usr/bin/time -v g++ -Wall -D__STDC_FORMAT_MACROS -O3 -c -o /dev/null -Isparsetools -I/usr/include/python2.7 sparsetools/bsr.cxx
Elapsed (wall clock) time (h:mm:ss or m:ss): 1:12.27
Maximum resident set size (kbytes): 672080

$ /usr/bin/time -v g++ -Wall -D__STDC_FORMAT_MACROS -O3 -c -o /dev/null -Isparsetools -I/usr/include/python2.7 sparsetools/csr.cxx
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:29.09
Maximum resident set size (kbytes): 469900

$ sloccount sparsetools (counting autogenerated files, too)
Total Physical Source Lines of Code (SLOC) = 10,302
```