Skip to content

Commit

Permalink
Build cython extension module when the source distribution is created…
Browse files Browse the repository at this point in the history
…, not on the fly. This means that zounds users don't need cython installed
  • Loading branch information
JohnVinyard committed Sep 1, 2017
1 parent 63109b1 commit b73ff75
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ install:
- conda update -q conda
# Useful for debugging any issues with conda
- conda info -a
- conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION numpy=1.12 scipy=0.18
- conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION numpy=1.12 scipy=0.18 cython
- source activate test-environment
- python setup.py install
- pip install coveralls
Expand Down
20 changes: 19 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from setuptools import setup
import re
import numpy as np
from distutils.extension import Extension


try:
import pypandoc
Expand All @@ -16,6 +19,21 @@
download_url = 'https://github.com/jvinyard/zounds/tarball/{version}'\
.format(**locals())


countbits = Extension(
name='countbits',
sources=['zounds/nputil/countbits.pyx'],
include_dirs=[np.get_include()],
extra_compile_args=[
'-shared',
'-pthread',
'-fPIC',
'-fwrapv',
'-O2',
'-Wall',
'-fno-strict-aliasing'
])

setup(
name='zounds',
version=version,
Expand All @@ -24,6 +42,7 @@
author_email='john.vinyard@gmail.com',
long_description=long_description,
download_url=download_url,
ext_modules=[countbits],
packages=[
'zounds',
'zounds.basic',
Expand All @@ -49,7 +68,6 @@
'requests',
'tornado',
'pysoundfile',
'cython',
'matplotlib',
'argparse'
],
Expand Down
5 changes: 4 additions & 1 deletion zounds/learn/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,10 @@ def _forward_func(self):
def x(d):
import numpy as np
axes = tuple(range(1, len(d.shape)))
return d / np.max(np.abs(d), axis=axes, keepdims=True)
m = np.max(np.abs(d), axis=axes, keepdims=True)
output = d / m
output[np.isnan(output)] = 0
return output

return x

Expand Down
8 changes: 8 additions & 0 deletions zounds/learn/test_instancescaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,11 @@ def test_backward_transform_reconstructs_data_3d(self):
transformed = model.pipeline.transform(inp)
inverted = transformed.inverse_transform()
np.testing.assert_allclose(inverted, inp)

def test_correctly_handles_max_of_zero(self):
model = self.get_model()
inp = np.random.random_sample((100, 30, 3)) - 0.5
inp[0, ...] = 0
transformed = model.pipeline.transform(inp)
inverted = transformed.inverse_transform()
np.testing.assert_allclose(inverted, inp)
3 changes: 0 additions & 3 deletions zounds/nputil/npx.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

import numpy as np
from numpy.lib.stride_tricks import as_strided as ast

import pyximport
pyximport.install()
from countbits import *


Expand Down

0 comments on commit b73ff75

Please sign in to comment.