Skip to content

Commit

Permalink
Use the latest version of numpy and scipy
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnVinyard committed Nov 8, 2018
1 parent da2690d commit 9307a55
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 53 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 -c pytorch -c hcc -c conda-forge python=$TRAVIS_PYTHON_VERSION numpy=1.12 scipy=0.19 cython pytorch=0.4 torchvision libsndfile=1.0.28 libsamplerate=0.1.8 libflac=1.3.1 libogg=1.3.2
- conda create -q -n test-environment -c pytorch -c hcc -c conda-forge python=$TRAVIS_PYTHON_VERSION numpy=1.15.3 scipy=1.1.0 cython pytorch=0.4 torchvision libsndfile=1.0.28 libsamplerate=0.1.8 libflac=1.3.1 libogg=1.3.2
- sudo ldconfig /opt/conda/lib
- source activate test-environment
- python setup.py install
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ RUN echo 'export PATH=/opt/conda/bin:$PATH' > /etc/profile.d/conda.sh \

ENV PATH /opt/conda/bin:$PATH

RUN conda install -y -c pytorch numpy=1.12 scipy=0.19 pytorch=0.4
RUN conda install -y -c pytorch numpy=1.15.3 scipy=1.1.0 pytorch=0.4

RUN pip install zounds

Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ tornado==4.5.3
pysoundfile
matplotlib==1.5.0
intervaltree
numpy==1.12.1
scipy==0.19
numpy==1.15.3
scipy==1.1.0
torch==0.4.0
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@
'argparse',
'intervaltree',
'ujson',
'numpy==1.12.1',
'scipy==0.19',
'numpy==1.15.3',
'scipy==1.1.0',
'torch==0.4.0'
],
package_data={
Expand Down
18 changes: 0 additions & 18 deletions zounds/core/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,24 +299,6 @@ def _new_dims(self, index, new_arr):
for dim in self.dimensions[dims_pos:]:
yield dim

def _wrap(self, other):
return self.__class__(other, self.dimensions)

def __gt__(self, other):
return self._wrap(np.asarray(self).__gt__(other))

def __ge__(self, other):
return self._wrap(np.asarray(self).__ge__(other))

def __lt__(self, other):
return self._wrap(np.asarray(self).__lt__(other))

def __le__(self, other):
return self._wrap(np.asarray(self).__le__(other))

def __eq__(self, other):
return self._wrap(np.asarray(self).__eq__(other))

def _tuplify(self, a):
if isinstance(a, list):
t = set(map(lambda x: x.__class__, a))
Expand Down
37 changes: 20 additions & 17 deletions zounds/spectral/sliding_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,26 @@ def _wdata(self, size):
self._cache[size] = window
return window

def __numpy_ufunc__(self, *args, **kwargs):
# KLUDGE: This seems really odd, but the mere presence of this
# numpy-specific magic method seems to serve as a hint to to call
# this instances __rmul__ implementation, instead of doing element-wise
# multiplication, as per:
# http://docs.scipy.org/doc/numpy/reference/arrays.classes.html#numpy.class.__numpy_ufunc__
raise NotImplementedError()

def __mul__(self, other):
size = other.shape[-1]
wdata = self._wdata(size)
if wdata is None:
return other
return wdata.astype(other.dtype) * other

def __rmul__(self, other):
return self.__mul__(other)
def __array_ufunc__(self, ufunc, method, *args, **kwargs):

if args[0] is self:
second_arg = args[1]
size = second_arg.shape[-1]
dtype = second_arg.dtype
wdata = self._wdata(size)
if wdata is None:
return second_arg
first_arg = wdata.astype(dtype)
else:
first_arg = args[0]
size = first_arg.shape[-1]
dtype = first_arg.dtype
wdata = self._wdata(size)
if wdata is None:
return first_arg
second_arg = wdata.astype(dtype)

return getattr(ufunc, method)(first_arg, second_arg, **kwargs)


class IdentityWindowingFunc(WindowingFunc):
Expand Down
6 changes: 6 additions & 0 deletions zounds/spectral/test_weighting.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,9 @@ def test_can_apply_weighting_to_filter_bank(self):
weighted = bank * AWeighting()
self.assertSequenceEqual(bank.dimensions, weighted.dimensions)

def test_multiplication_by_weighting_is_commutative(self):
sr = SR11025()
band = FrequencyBand(20, sr.nyquist)
scale = MelScale(band, 100)
bank = fir_filter_bank(scale, 256, sr, np.hanning(25))
np.testing.assert_allclose(bank * AWeighting(), AWeighting() * bank)
23 changes: 11 additions & 12 deletions zounds/spectral/weighting.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,17 @@ def _get_factors(self, arr):

raise ValueError('arr must have a frequency dimension')

def __mul__(self, other):
factors = self._get_factors(other)
return factors * other

def __rmul__(self, other):
return self.__mul__(other)

def __div__(self, other):
return other / self._get_factors(other)

def __rdiv__(self, other):
return self.__div__(other)
def __array_ufunc__(self, ufunc, method, *args, **kwargs):
if ufunc == np.multiply or ufunc == np.divide:
if args[0] is self:
first_arg = self._get_factors(args[1])
second_arg = args[1]
else:
first_arg = args[0]
second_arg = self._get_factors(args[0])
return getattr(ufunc, method)(first_arg, second_arg, **kwargs)
else:
return NotImplemented


class AWeighting(FrequencyWeighting):
Expand Down

0 comments on commit 9307a55

Please sign in to comment.