Skip to content

Commit

Permalink
Merge pull request #133 from r9y9/np2
Browse files Browse the repository at this point in the history
relax numpy requirement and support numpy 2.0.0
  • Loading branch information
r9y9 authored Jun 29, 2024
2 parents ccf2f76 + 996f6f5 commit 928ff6f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,20 @@ jobs:
brew install libsamplerate
;;
esac
- name: Install dependencies
- name: Install dependencies (Linux and macOS)
if: runner.os != 'Windows'
run: |
python -m pip install --upgrade pip
pip install torch
pip install -e ".[test,lint]"
# NOTE: window is not happy with numpy 2.0.0
- name: Install dependencies (Windows)
if: runner.os == 'Windows'
run: |
python -m pip install --upgrade pip
pip install "numpy<2.0.0"
pip install torch
pip install -e ".[test,lint]"
- name: Lint with pysen
run: |
pysen run lint
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = [
"wheel",
"setuptools",
"cython>=0.21.0",
"numpy>=v1.20.0, <2",
"numpy>=v1.20.0",
"scipy",
]

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def package_files(directory):
"scikit-learn",
"pysptk >= 0.1.17",
"tqdm",
"numpy >= 1.20.0, <2",
"numpy >= 1.20.0",
]

setup(
Expand Down
19 changes: 17 additions & 2 deletions tests/test_preprocessing.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import librosa
import numpy as np
import pysptk
import pytest
import pyworld
from nnmnkwii import preprocessing as P
from nnmnkwii.datasets import FileSourceDataset, PaddedFileSourceDataset
from nnmnkwii.preprocessing import (
Expand All @@ -20,8 +18,17 @@
example_file_data_sources_for_acoustic_model,
example_file_data_sources_for_duration_model,
)
from packaging.version import Version
from scipy.io import wavfile

try:
import pyworld

pyworld_available = True
except ValueError:
# ValueError: numpy.dtype size changed, may indicate binary incompatibility.
pyworld_available = False


def _get_windows_set_bandmat():
windows_set = [
Expand Down Expand Up @@ -271,6 +278,7 @@ def test_interp1d():
assert np.all(if0 != 0)


@pytest.mark.skipif(not pyworld_available, reason="pyworld is not available")
def test_trim_remove_zeros_frames():
fs, x = wavfile.read(example_audio_file())
frame_period = 5
Expand Down Expand Up @@ -449,12 +457,19 @@ def test_dtw_frame_length_adjustment():
assert X_aligned.shape == Y_aligned.shape


@pytest.mark.skipif(
Version(np.__version__) >= Version("2.0.0"), reason="numpy >= 2.0.0"
)
@pytest.mark.skipif(not pyworld_available, reason="pyworld is not available")
def test_dtw_aligner():
from nnmnkwii.preprocessing.alignment import DTWAligner, IterativeDTWAligner

fs, x = wavfile.read(example_audio_file())
x = (x / 32768.0).astype(np.float32)
assert fs == 16000
# NOTE: librosa deps need to be updated for numpy 2.0.0
import librosa

x_fast = librosa.effects.time_stretch(x, rate=2.0)

X = _get_mcep(x, fs)
Expand Down
15 changes: 13 additions & 2 deletions tests/test_real_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import numpy as np
import pysptk
import pytest
import pyworld

# Data source implementations
from nnmnkwii.datasets import (
Expand All @@ -21,7 +20,13 @@
from nnmnkwii.preprocessing import trim_zeros_frames
from scipy.io import wavfile

# Tests marked with "require_local_data" needs data to be downloaded.
try:
import pyworld

pyworld_available = True
except ValueError:
# ValueError: numpy.dtype size changed, may indicate binary incompatibility.
pyworld_available = False


def test_cmu_arctic_dummy():
Expand Down Expand Up @@ -142,6 +147,7 @@ def f(source):
@pytest.mark.skipif(
not (Path.home() / "data" / "cmu_arctic").exists(), reason="Data doesn't exist"
)
@pytest.mark.skipif(not pyworld_available, reason="pyworld is not available")
def test_cmu_arctic():
DATA_DIR = join(expanduser("~"), "data", "cmu_arctic")
if not exists(DATA_DIR):
Expand Down Expand Up @@ -205,6 +211,7 @@ def collect_features(self, path):
not (Path.home() / "data" / "voice-statistics").exists(),
reason="Data doesn't exist",
)
@pytest.mark.skipif(not pyworld_available, reason="pyworld is not available")
def test_voice_statistics():
DATA_DIR = join(expanduser("~"), "data", "voice-statistics")
if not exists(DATA_DIR):
Expand Down Expand Up @@ -303,6 +310,7 @@ def collect_features(self, path):
@pytest.mark.skipif(
not (Path.home() / "data" / "LJSpeech-1.1").exists(), reason="Data doesn't exist"
)
@pytest.mark.skipif(not pyworld_available, reason="pyworld is not available")
def test_ljspeech():
DATA_DIR = join(expanduser("~"), "data", "LJSpeech-1.1")
if not exists(DATA_DIR):
Expand Down Expand Up @@ -355,6 +363,7 @@ def collect_features(self, path):
@pytest.mark.skipif(
not (Path.home() / "data" / "vcc2016").exists(), reason="Data doesn't exist"
)
@pytest.mark.skipif(not pyworld_available, reason="pyworld is not available")
def test_vcc2016():
DATA_DIR = join(expanduser("~"), "data", "vcc2016")
if not exists(DATA_DIR):
Expand Down Expand Up @@ -417,6 +426,7 @@ def collect_features(self, path):
@pytest.mark.skipif(
not (Path.home() / "data" / "jsut_ver1.1").exists(), reason="Data doesn't exist"
)
@pytest.mark.skipif(not pyworld_available, reason="pyworld is not available")
def test_jsut():
DATA_DIR = join(expanduser("~"), "data", "jsut_ver1.1")
if not exists(DATA_DIR):
Expand Down Expand Up @@ -475,6 +485,7 @@ def collect_features(self, path):
@pytest.mark.skipif(
not (Path.home() / "data" / "VCTK-Corpus").exists(), reason="Data doesn't exist"
)
@pytest.mark.skipif(not pyworld_available, reason="pyworld is not available")
def test_vctk():
DATA_DIR = join(expanduser("~"), "data", "VCTK-Corpus")
if not exists(DATA_DIR):
Expand Down

0 comments on commit 928ff6f

Please sign in to comment.