Skip to content

Commit

Permalink
fix: drop ctypes
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Aug 11, 2022
1 parent 94f3443 commit ca99b44
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
1 change: 0 additions & 1 deletion init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
# Linux/MacOS 下初始化 monotonic_align 模块
cd monotonic_align
python3 setup.py build_ext --inplace
mv monotonic_align/*.so core.dll
18 changes: 8 additions & 10 deletions monotonic_align/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
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 monotonic_align.monotonic_align.core import maximum_path_c

def maximum_path(neg_cent, mask):
""" Cython optimized version.
Expand All @@ -11,10 +9,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 ca99b44

Please sign in to comment.