Skip to content

Commit

Permalink
Merge pull request CjangCjengh#5 from fumiama/master
Browse files Browse the repository at this point in the history
fix: drop ctypes
  • Loading branch information
CjangCjengh authored Aug 11, 2022
2 parents f10ad62 + eaa3eaa commit 6a0924b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -371,4 +371,5 @@ monotonic_align/core.c

# data
/config.json
/*.pth
/*.pth
*.wav
6 changes: 0 additions & 6 deletions init.sh

This file was deleted.

20 changes: 11 additions & 9 deletions monotonic_align/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import numpy as np
import torch
from ctypes import cdll
maximum_path_c = cdll.LoadLibrary('./monotonic_align/core.dll')
from numpy import zeros, int32, float32
from torch import from_numpy

from os import system
system("cd monotonic_align && python3 setup.py build_ext --inplace")

from .monotonic_align.core import maximum_path_c

def maximum_path(neg_cent, mask):
""" Cython optimized version.
Expand All @@ -11,10 +13,10 @@ def maximum_path(neg_cent, mask):
"""
device = neg_cent.device
dtype = neg_cent.dtype
neg_cent = neg_cent.data.cpu().numpy().astype(np.float32)
path = np.zeros(neg_cent.shape, dtype=np.int32)
neg_cent = neg_cent.data.cpu().numpy().astype(float32)
path = zeros(neg_cent.shape, dtype=int32)

t_t_max = mask.sum(1)[:, 0].data.cpu().numpy().astype(np.int32)
t_s_max = mask.sum(2)[:, 0].data.cpu().numpy().astype(np.int32)
t_t_max = mask.sum(1)[:, 0].data.cpu().numpy().astype(int32)
t_s_max = mask.sum(2)[:, 0].data.cpu().numpy().astype(int32)
maximum_path_c(path, neg_cent, t_t_max, t_s_max)
return torch.from_numpy(path).to(device=device, dtype=dtype)
return from_numpy(path).to(device=device, dtype=dtype)

0 comments on commit 6a0924b

Please sign in to comment.