scikit-learn/scikit-learn — pull request #557 by ogrisel (2012-01-16 00:49:13+00:00)
Title: HLP: trying to wrap MurmurHash3

Hi all,

I am trying to make a cython wrapper for the fast hash function called murmurhash which arguably (one of) the fastest (non-cryptographic) hash function used in machine learning.

I would like to use it to make some experiments in the Random Projection branch and build an efficient hashing vectorizer to implement the hashing trick:

http://metaoptimize.com/qa/questions/6943/what-is-the-hashing-trick

However my cython / c++ / distutils fu is less.

Maybe @fabian could have a quick look? When I run the test I get:

```
nosetests sklearn/utils/tests/test_murmurhash.py
E
======================================================================
ERROR: Failure: ImportError (/home/ogrisel/coding/scikit-learn/sklearn/utils/murmurhash.so: undefined symbol: MurmurHash3_x86_32)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/nose/loader.py", line 390, in loadTestsFromName
addr.filename, addr.module)
File "/usr/local/lib/python2.7/dist-packages/nose/importer.py", line 39, in importFromPath
return self.importFromDir(dir_path, fqname)
File "/usr/local/lib/python2.7/dist-packages/nose/importer.py", line 86, in importFromDir
mod = load_module(part_fqname, fh, filename, desc)
File "/home/ogrisel/coding/scikit-learn/sklearn/utils/tests/test_murmurhash.py", line 1, in
from sklearn.utils.murmurhash import murmurhash3
ImportError: /home/ogrisel/coding/scikit-learn/sklearn/utils/murmurhash.so: undefined symbol: MurmurHash3_x86_32

----------------------------------------------------------------------
Ran 1 test in 0.001s

FAILED (errors=1)
```

However my setup.py is building a library called `libMurmurHash3.a` successfully and it is passed in the C flags used for building the `murmurhash.so` extension:

```
building 'MurmurHash3' library
compiling C++ sources
C compiler: g++ -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -fPIC

compile options: '-I/usr/lib/pymodules/python2.7/numpy/core/include -c'
g++: sklearn/utils/src/MurmurHash3.cpp
ar: adding 1 object files to build/temp.linux-x86_64-2.7/libMurmurHash3.a
customize UnixCCompiler
customize UnixCCompiler using build_ext
resetting extension 'sklearn.svm.liblinear' language from 'c' to 'c++'.
customize UnixCCompiler
customize UnixCCompiler using build_ext
building 'sklearn.utils.murmurhash' extension
compiling C sources
C compiler: gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC

compile options: '-Isklearn/utils/src -I/usr/lib/pymodules/python2.7/numpy/core/include -I/usr/include/python2.7 -c'
gcc: sklearn/utils/murmurhash.c
g++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions build/temp.linux-x86_64-2.7/sklearn/utils/murmurhash.o -Lbuild/temp.linux-x86_64-2.7 -lMurmurHash3 -o sklearn/utils/murmurhash.so
running scons
```

I don't get any build error. What am I doing wrong?