Skip to content

Commit

Permalink
Merge pull request #88 from r9y9/py37-fix-bandmat
Browse files Browse the repository at this point in the history
tentative fix: make bandmat optional requirement for python 3.7
  • Loading branch information
r9y9 authored Jul 6, 2019
2 parents 52e8ecb + bc439ee commit e5854bb
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 17 deletions.
11 changes: 9 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ language: python
python:
- "2.7"
- "3.6"
- "3.7"

notifications:
email: false

before_install:
- sudo apt-get update
- if [["$TRAVIS_PYTHON_VERSION" == "2.7"]]; then
- if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
wget http://repo.continuum.io/miniconda/Miniconda-3.8.3-Linux-x86_64.sh -O miniconda.sh;
else
wget http://repo.continuum.io/miniconda/Miniconda3-3.8.3-Linux-x86_64.sh -O miniconda.sh;
Expand All @@ -34,7 +35,13 @@ install:
- pip install -e ".[test]"

script:
- nosetests --with-coverage --cover-package=nnmnkwii -v -w tests/ -a '!require_local_data,!modspec'
# Workaround for bandmat installation issue on python 3.7
# see https://github.com/MattShannon/bandmat/issues/10
- if [[ "$TRAVIS_PYTHON_VERSION" == "3.7" ]]; then
nosetests --with-coverage --cover-package=nnmnkwii -v -w tests/ -a '!require_local_data,!modspec,!requires_bandmat' --ignore-files=test_autograd.py;
else
nosetests --with-coverage --cover-package=nnmnkwii -v -w tests/ -a '!require_local_data,!modspec';
fi
- flake8

after_success:
Expand Down
1 change: 0 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ install:
- "SET PATH=%MINICONDA%;%MINICONDA%\\Scripts;%PATH%"
- conda config --set always_yes yes --set changeps1 no
- conda update -q conda
- conda install -n root _license
- conda info -a
- "conda create -q -n test-environment python=%PYTHON_VERSION% numpy scipy cython nose pytorch -c pytorch"
- activate test-environment
Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Change log
v0.0.19 <2019-xx-xx>
--------------------

- `#88`_: Tentative fix: make bandmat optional requirement as it is causing installation errors on python 3.7. See [here](https://github.com/MattShannon/bandmat/issues/10) for details.
- `#85`_: Fixed rounding error in caluculating number of frames.
- `#87`_: Fixed :func:`nnmnkwii.preprocessing.trim_zeros_frames` issue. Support passing ``trim`` argument.

Expand Down Expand Up @@ -177,3 +178,4 @@ v0.0.1 <2017-08-14>
.. _#79: https://github.com/r9y9/nnmnkwii/pull/79
.. _#85: https://github.com/r9y9/nnmnkwii/issues/85
.. _#87: https://github.com/r9y9/nnmnkwii/pull/87
.. _#88: https://github.com/r9y9/nnmnkwii/pull/88
11 changes: 11 additions & 0 deletions nnmnkwii/paramgen/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
from __future__ import with_statement, print_function, absolute_import


try:
import bandmat
except ImportError:
raise ImportError("""
`bandmat` is required for the `paramgen` module but not found.
Please install it manually by:
`pip install bandmat`.
If you see installation errors, please report to https://github.com/MattShannon/bandmat.
""")

from ._mlpg import build_win_mats, mlpg, mlpg_grad, unit_variance_mlpg_matrix
from ._mlpg import reshape_means, full_window_mat

Expand Down
26 changes: 17 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from os.path import join, exists
import subprocess
import os
import sys

version = '0.0.19'

Expand Down Expand Up @@ -59,6 +60,7 @@ def run(self):
build_py.create_version_file()
setuptools.command.develop.develop.run(self)


cmdclass = {"build_py": build_py, "develop": develop}

min_cython_ver = '0.28.0'
Expand Down Expand Up @@ -118,6 +120,20 @@ def package_files(directory):

package_data = package_files("./nnmnkwii/util/_example_data")

install_requires = [
'scipy',
'cython >= ' + min_cython_ver,
'fastdtw',
'sklearn',
'pysptk >= 0.1.17',
'tqdm',
]

# Workaround for python 3.7 and bandmat
# https://github.com/r9y9/deepvoice3_pytorch/issues/154
if sys.version_info[:2] != (3, 7):
install_requires.append('bandmat >= 0.7')

setup(
name='nnmnkwii',
version=version,
Expand All @@ -133,15 +149,7 @@ def package_files(directory):
ext_modules=ext_modules,
cmdclass=cmdclass,
setup_requires=["numpy >= 1.11.0"],
install_requires=[
'scipy',
'cython >= ' + min_cython_ver,
'bandmat >= 0.7',
'fastdtw',
'sklearn',
'pysptk >= 0.1.17',
'tqdm',
],
install_requires=install_requires,
tests_require=['nose', 'coverage'],
extras_require={
'docs': ['numpydoc', 'sphinx_rtd_theme'],
Expand Down
3 changes: 3 additions & 0 deletions tests/test_autograd.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from __future__ import division, print_function, absolute_import


# Note: Tests in the file tightly depends on MLPG and bandmat

from nnmnkwii.autograd._impl.mlpg import MLPG, UnitVarianceMLPG
from nnmnkwii.autograd._impl.modspec import ModSpec
from nnmnkwii import paramgen as G
Expand Down
8 changes: 7 additions & 1 deletion tests/test_baseline.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from __future__ import division, print_function, absolute_import

from nnmnkwii.baseline.gmm import MLPG
import numpy as np
from sklearn.mixture import GaussianMixture
from os.path import join, dirname
from numpy.linalg import norm
from nose.plugins.attrib import attr

DATA_DIR = join(dirname(__file__), "data")

Expand All @@ -30,7 +30,10 @@ def _get_windows_set():
return windows_set


@attr("requires_bandmat")
def test_diffvc():
from nnmnkwii.baseline.gmm import MLPG

# MLPG is performed dimention by dimention, so static_dim 1 is enough, 2 just for in
# case.
static_dim = 2
Expand Down Expand Up @@ -60,7 +63,10 @@ def test_diffvc():
assert norm(tgt_mc - mc_converted1) < norm(src_mc - mc_converted1)


@attr("requires_bandmat")
def test_gmmmap_swap():
from nnmnkwii.baseline.gmm import MLPG

static_dim = 2
T = 10
windows = _get_windows_set()[-1]
Expand Down
12 changes: 11 additions & 1 deletion tests/test_paramgen.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import division, print_function, absolute_import

from nnmnkwii import paramgen as G
import numpy as np

from nose.plugins.attrib import attr


def _get_windows_set():
windows_set = [
Expand All @@ -25,7 +26,10 @@ def _get_windows_set():
return windows_set


@attr("requires_bandmat")
def test_mlpg():
from nnmnkwii import paramgen as G

static_dim = 2
T = 10

Expand Down Expand Up @@ -54,7 +58,9 @@ def test_mlpg():
assert np.allclose(generated1, generated2)


@attr("requires_bandmat")
def test_mlpg_window_full():
from nnmnkwii import paramgen as G
static_dim = 2
T = 10

Expand All @@ -73,7 +79,9 @@ def full_window_mat_native(win_mats, T):
assert np.allclose(full_window_mat_native(win_mats, T), fullwin)


@attr("requires_bandmat")
def test_unit_variance_mlpg():
from nnmnkwii import paramgen as G
static_dim = 2
T = 10

Expand All @@ -87,7 +95,9 @@ def test_unit_variance_mlpg():
assert np.allclose(y_hat, y)


@attr("requires_bandmat")
def test_reshape_means():
from nnmnkwii import paramgen as G
static_dim = 2
T = 10

Expand Down
9 changes: 8 additions & 1 deletion tests/test_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from nnmnkwii.preprocessing import trim_zeros_frames, remove_zeros_frames
from nnmnkwii.preprocessing import adjust_frame_lengths, delta_features
from nnmnkwii.preprocessing import adjust_frame_length
from nnmnkwii.preprocessing.alignment import DTWAligner, IterativeDTWAligner
from nnmnkwii.preprocessing import modspec, modphase
from nnmnkwii.preprocessing import preemphasis, inv_preemphasis
from nnmnkwii import preprocessing as P
Expand All @@ -21,6 +20,8 @@
import librosa
import pysptk

from nose.plugins.attrib import attr


def _get_windows_set():
windows_set = [
Expand Down Expand Up @@ -404,7 +405,10 @@ def _get_mcep(x, fs, frame_period=5, order=24):
return mc


@attr("requires_bandmat")
def test_dtw_frame_length_adjustment():
from nnmnkwii.preprocessing.alignment import DTWAligner, IterativeDTWAligner

_, X = example_file_data_sources_for_duration_model()
X = FileSourceDataset(X)
X_unaligned = X.asarray()
Expand All @@ -418,7 +422,10 @@ def test_dtw_frame_length_adjustment():
assert X_aligned.shape == Y_aligned.shape


@attr("requires_bandmat")
def test_dtw_aligner():
from nnmnkwii.preprocessing.alignment import DTWAligner, IterativeDTWAligner

x, fs = librosa.load(example_audio_file(), sr=None)
assert fs == 16000
x_fast = librosa.effects.time_stretch(x, 2.0)
Expand Down
9 changes: 7 additions & 2 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

from nnmnkwii.util import apply_each2d_padded, apply_each2d_trim
from nnmnkwii.util.linalg import cholesky_inv, cholesky_inv_banded
from nnmnkwii.paramgen import build_win_mats

import numpy as np
import scipy.linalg
import bandmat as bm

from nose.plugins.attrib import attr


def _get_windows_set():
Expand Down Expand Up @@ -55,14 +55,19 @@ def dummmy_func2d(x):


def _get_banded_test_mat(win_mats, T):
import bandmat as bm

sdw = max([win_mat.l + win_mat.u for win_mat in win_mats])
P = bm.zeros(sdw, sdw, T)
for win_index, win_mat in enumerate(win_mats):
bm.dot_mm_plus_equals(win_mat.T, win_mat, target_bm=P)
return P


@attr("requires_bandmat")
def test_linalg_choleskey_inv():
from nnmnkwii.paramgen import build_win_mats

for windows in _get_windows_set():
for T in [5, 10]:
win_mats = build_win_mats(windows, T)
Expand Down

0 comments on commit e5854bb

Please sign in to comment.