Skip to content

Commit

Permalink
Merge pull request #130 from r9y9/ryuichi/ciupdate
Browse files Browse the repository at this point in the history
Support Python 3.10+
  • Loading branch information
r9y9 authored Jun 28, 2024
2 parents 2f82535 + 892300a commit c67e6da
Show file tree
Hide file tree
Showing 21 changed files with 125 additions and 153 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ jobs:
python-version: 3.8
- os: ubuntu-latest
python-version: 3.9
# TODO: https://github.com/r9y9/nnmnkwii/issues/124
# - os: ubuntu-latest
# python-version: '3.10'
- os: ubuntu-latest
python-version: '3.10'
- os: ubuntu-latest
python-version: '3.11'
- os: macos-latest
python-version: 3.9
- os: windows-latest
Expand Down Expand Up @@ -59,4 +60,4 @@ jobs:
pysen run lint
- name: Test
run: |
nosetests --with-coverage --cover-package=nnmnkwii -v -w tests/ -a '!require_local_data,!modspec'
pytest --cov=nnmnkwii --cov-report xml -v tests/
2 changes: 0 additions & 2 deletions nnmnkwii/datasets/cmu_arctic.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, print_function, with_statement

from os import listdir
from os.path import isdir, join, splitext

Expand Down
2 changes: 0 additions & 2 deletions nnmnkwii/datasets/ljspeech.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, print_function, with_statement

from os.path import exists, join

import numpy as np
Expand Down
3 changes: 0 additions & 3 deletions nnmnkwii/datasets/vcc2016.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# coding: utf-8
from __future__ import absolute_import, print_function, with_statement

from os import listdir
from os.path import isdir, join, splitext

Expand Down
2 changes: 0 additions & 2 deletions nnmnkwii/frontend/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, division, print_function

NOTE_MAPPING = {
"A0": 21,
"Bb0": 22,
Expand Down
1 change: 0 additions & 1 deletion nnmnkwii/functions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
from nnmnkwii.paramgen import * # noqa
from nnmnkwii.postfilters import * # noqa
from nnmnkwii.preprocessing import * # noqa
2 changes: 0 additions & 2 deletions nnmnkwii/metrics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, print_function, with_statement

import math

import numpy as np
Expand Down
3 changes: 0 additions & 3 deletions nnmnkwii/util/linalg.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# coding: utf-8
from __future__ import absolute_import, division, print_function

import numpy as np

from ._linalg import cholesky_inv_banded as _cholesky_inv_banded
Expand Down
2 changes: 0 additions & 2 deletions perf/autograd_mlpg_perf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, division, print_function

import sys
import time

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ def package_files(directory):
ext_modules=ext_modules,
cmdclass=cmdclass,
install_requires=install_requires,
tests_require=["nose", "coverage"],
tests_require=["pytest", "pytest-cov", "coverage"],
extras_require={
"docs": ["numpydoc", "sphinx_rtd_theme"],
"test": ["nose", "pyworld", "librosa"],
"test": ["pytest", "pytest-cov", "pyworld", "librosa"],
"lint": [
"pysen",
"types-setuptools",
Expand Down
40 changes: 18 additions & 22 deletions tests/test_autograd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from nnmnkwii import autograd as AF
from nnmnkwii import paramgen as G
from nnmnkwii.autograd._impl.mlpg import MLPG, UnitVarianceMLPG
from nnmnkwii.autograd._impl.modspec import ModSpec
from nose.plugins.attrib import attr
from torch import nn
from torch.autograd import gradcheck

Expand Down Expand Up @@ -220,23 +218,21 @@ def test_mlpg_variance_expand():
assert np.allclose(y.data.numpy(), y_hat.data.numpy())


@attr("modspec")
def test_modspec_gradcheck():
static_dim = 12
T = 16
torch.manual_seed(1234)
n = 16
for norm in [None, "ortho"]:
inputs = (torch.rand(T, static_dim, requires_grad=True), n, norm)
assert gradcheck(ModSpec.apply, inputs, eps=1e-4, atol=1e-4)


@attr("modspec")
def test_modspec_gradcheck_large_n():
static_dim = 12
T = 16
torch.manual_seed(1234)
for n in [16, 32]:
for norm in [None, "ortho"]:
inputs = (torch.rand(T, static_dim, requires_grad=True), n, norm)
assert gradcheck(ModSpec.apply, inputs, eps=1e-4, atol=1e-4)
# def test_modspec_gradcheck():
# static_dim = 12
# T = 16
# torch.manual_seed(1234)
# n = 16
# for norm in [None, "ortho"]:
# inputs = (torch.rand(T, static_dim, requires_grad=True), n, norm)
# assert gradcheck(ModSpec.apply, inputs, eps=1e-4, atol=1e-4)


# def test_modspec_gradcheck_large_n():
# static_dim = 12
# T = 16
# torch.manual_seed(1234)
# for n in [16, 32]:
# for norm in [None, "ortho"]:
# inputs = (torch.rand(T, static_dim, requires_grad=True), n, norm)
# assert gradcheck(ModSpec.apply, inputs, eps=1e-4, atol=1e-4)
3 changes: 0 additions & 3 deletions tests/test_baseline.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from os.path import dirname, join

import numpy as np
from nose.plugins.attrib import attr
from numpy.linalg import norm
from sklearn.mixture import GaussianMixture

Expand Down Expand Up @@ -29,7 +28,6 @@ def _get_windows_set():
return windows_set


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

Expand Down Expand Up @@ -62,7 +60,6 @@ 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

Expand Down
38 changes: 17 additions & 21 deletions tests/test_datasets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from os.path import dirname, join

import numpy as np
import pytest
from nnmnkwii.datasets import (
FileDataSource,
FileSourceDataset,
Expand All @@ -11,8 +12,6 @@
example_file_data_sources_for_acoustic_model,
example_file_data_sources_for_duration_model,
)
from nose.plugins.attrib import attr
from nose.tools import raises

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

Expand Down Expand Up @@ -45,7 +44,8 @@ def __test_outof_range(X):
print(X[0])

# Should raise IndexError
yield raises(IndexError)(__test_outof_range), X
with pytest.raises(IndexError):
__test_outof_range(X)


def test_invalid_dataset():
Expand All @@ -71,19 +71,19 @@ def __test_wrong_num_collected_files():
X = FileSourceDataset(WrongNumberOfCollectedFilesDataSource())
X[0]

yield raises(TypeError)(__test_wrong_num_args)
yield raises(ValueError)(__test_wrong_num_collected_files)
with pytest.raises(TypeError):
__test_wrong_num_args()
with pytest.raises(ValueError):
__test_wrong_num_collected_files()


@attr("pickle")
def test_asarray_tqdm():
# verbose=1 triggers tqdm progress report
for padded in [True, False]:
X, _ = _get_small_datasets(padded=padded, duration=True)
X.asarray(verbose=1)


@attr("pickle")
def test_asarray():
X, Y = _get_small_datasets(padded=False, duration=True)
lengths = [len(x) for x in X]
Expand All @@ -110,17 +110,16 @@ def __test_very_small_padded_length():
X.asarray(padded_length=1)

# Should raise `num frames exceeded`
yield raises(RuntimeError)(__test_very_small_padded_length)
with pytest.raises(RuntimeError):
__test_very_small_padded_length()


@attr("pickle")
def test_duration_sources():
X, Y = _get_small_datasets(padded=False, duration=True)
for idx, (x, y) in enumerate(zip(X, Y)):
print(idx, x.shape, y.shape)


@attr("pickle")
def test_slice():
X, _ = _get_small_datasets(padded=False)
x = X[:2]
Expand All @@ -133,14 +132,12 @@ def test_slice():
assert len(x.shape) == 3 and x.shape[0] == 2


@attr("pickle")
def test_variable_length_sequence_wise_iteration():
X, Y = _get_small_datasets(padded=False)
for idx, (x, y) in enumerate(zip(X, Y)):
print(idx, x.shape, y.shape)


@attr("pickle")
def test_fixed_length_sequence_wise_iteration():
X, Y = _get_small_datasets(padded=True)

Expand All @@ -153,7 +150,6 @@ def test_fixed_length_sequence_wise_iteration():
assert y.shape[0] == Ty


@attr("pickle")
def test_frame_wise_iteration():
X, Y = _get_small_datasets(padded=False)

Expand Down Expand Up @@ -181,7 +177,6 @@ def test_frame_wise_iteration():
pass


@attr("pickle")
def test_sequence_wise_torch_data_loader():
import torch
from torch.utils import data as data_utils
Expand Down Expand Up @@ -210,19 +205,20 @@ def __test(X, Y, batch_size):
print(idx, x.shape, y.shape)

# Test with batch_size = 1
yield __test, X, Y, 1
__test(X, Y, 1)
# Since we have variable length frames, batch size larger than 1 causes
# runtime error.
yield raises(RuntimeError)(__test), X, Y, 2
with pytest.raises(RuntimeError):
__test(X, Y, 2)

# For padded dataset, which can be reprensented by (N, T^max, D), batchsize
# can be any number.
X, Y = _get_small_datasets(padded=True)
yield __test, X, Y, 1
yield __test, X, Y, 2
__test(X, Y, 1)
__test(X, Y, 2)


@attr("pickle")
# @attr("pickle")
def test_frame_wise_torch_data_loader():
import torch
from torch.utils import data as data_utils
Expand Down Expand Up @@ -259,5 +255,5 @@ def __test(X, Y, batch_size):
assert len(x.shape) == 2
assert len(y.shape) == 2

yield __test, X, Y, 128
yield __test, X, Y, 256
__test(X, Y, 128)
__test(X, Y, 256)
17 changes: 10 additions & 7 deletions tests/test_frontend.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from os.path import dirname, join

import numpy as np
import pytest
from nnmnkwii.frontend import merlin as fe
from nnmnkwii.io import hts
from nnmnkwii.util import example_label_file, example_question_file
from nose.tools import raises

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

Expand All @@ -14,7 +14,7 @@ def test_invalid_linguistic_features():
phone_labels = hts.load(example_label_file(phone_level=True))
state_labels = hts.load(example_label_file(phone_level=False))

@raises(ValueError)
# @raises(ValueError)
def __test(labels, subphone_features, add_frame_features):
fe.linguistic_features(
labels,
Expand All @@ -24,19 +24,22 @@ def __test(labels, subphone_features, add_frame_features):
add_frame_features=add_frame_features,
)

yield __test, phone_labels, "full", True
yield __test, phone_labels, "full", False
yield __test, state_labels, "full", False
with pytest.raises(ValueError):
__test(phone_labels, "full", True)
with pytest.raises(ValueError):
__test(phone_labels, "full", False)
with pytest.raises(ValueError):
__test(state_labels, "full", False)


def test_invalid_duration_features():
phone_labels = hts.load(example_label_file(phone_level=True))

@raises(ValueError)
def __test(labels, unit_size, feature_size):
fe.duration_features(labels, unit_size=unit_size, feature_size=feature_size)

yield __test, phone_labels, None, "frame"
with pytest.raises(ValueError):
__test(phone_labels, None, "frame")


def test_silence_frame_removal_given_hts_labels():
Expand Down
Loading

0 comments on commit c67e6da

Please sign in to comment.