-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathbinding.cpp
67 lines (51 loc) · 1.74 KB
/
binding.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "edit-distance.h"
#include <torch/types.h>
#define CHECK_CUDA(x) TORCH_CHECK(x.device().is_cuda(), #x " must be a CUDA tensor")
#define CHECK_CONTIGUOUS(x) TORCH_CHECK(x.is_contiguous(), #x " must be contiguous")
#define CHECK_INPUT(x) CHECK_CUDA(x); CHECK_CONTIGUOUS(x)
void CollapseRepeated(
torch::Tensor source,
torch::Tensor length) {
CHECK_INPUT(source);
CHECK_INPUT(length);
CollapseRepeatedCuda(source, length);
}
void RemoveBlank(
torch::Tensor source,
torch::Tensor length,
torch::Tensor blank) {
CHECK_INPUT(source);
CHECK_INPUT(length);
CHECK_INPUT(blank);
RemoveBlankCuda(source, length, blank);
}
void StripSeparator(
torch::Tensor source,
torch::Tensor length,
torch::Tensor separator) {
CHECK_INPUT(source);
CHECK_INPUT(length);
CHECK_INPUT(separator);
StripSeparatorCuda(source, length, separator);
}
torch::Tensor LevenshteinDistance(
torch::Tensor source,
torch::Tensor target,
torch::Tensor source_length,
torch::Tensor target_length,
torch::Tensor blank,
torch::Tensor separator) {
CHECK_INPUT(source);
CHECK_INPUT(target);
CHECK_INPUT(source_length);
CHECK_INPUT(target_length);
CHECK_INPUT(blank);
CHECK_INPUT(separator);
return LevenshteinDistanceCuda(source, target, source_length, target_length, blank, separator);
}
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
m.def("collapse_repeated", &CollapseRepeated, "Merge repeated tokens");
m.def("remove_blank", &RemoveBlank, "Remove blank");
m.def("strip_separator", &StripSeparator, "Strip separator");
m.def("levenshtein_distance", &LevenshteinDistance, "Levenshtein distance");
}