-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rewrite pybind interface for Array2 and Fsa
- Loading branch information
Showing
18 changed files
with
512 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
pybind11_add_module(_k2 | ||
array.cc | ||
fsa.cc | ||
fsa_algo.cc | ||
fsa_util.cc | ||
k2.cc | ||
tensor.cc | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// k2/python/csrc/fsa_algo.cc | ||
|
||
// Copyright (c) 2020 Xiaomi Corporation (author: Haowen Qiu) | ||
|
||
// See ../../../LICENSE for clarification regarding multiple authors | ||
|
||
#include "k2/python/csrc/fsa_algo.h" | ||
|
||
#include <memory> | ||
#include <utility> | ||
|
||
#include "k2/csrc/arcsort.h" | ||
#include "k2/csrc/array.h" | ||
#include "k2/python/csrc/array.h" | ||
|
||
namespace k2 {} // namespace k2 | ||
|
||
void PyBindArcSort(py::module &m) { | ||
using PyClass = k2::ArcSorter; | ||
py::class_<PyClass>(m, "_ArcSorter") | ||
.def(py::init<const k2::Fsa &>(), py::arg("fsa_in")) | ||
.def("get_sizes", &PyClass::GetSizes, py::arg("fsa_size")) | ||
.def( | ||
"get_output", | ||
[](PyClass &self, k2::Fsa *fsa_out, | ||
k2::Array1<int32_t *> *arc_map = nullptr) { | ||
self.GetOutput(fsa_out, | ||
arc_map == nullptr ? nullptr : arc_map->data); | ||
}, | ||
py::arg("fsa_out"), | ||
py::arg("arc_map") = (k2::Array1<int32_t *> *)nullptr); | ||
|
||
m.def( | ||
"_arc_sort", | ||
[](k2::Fsa *fsa, k2::Array1<int32_t *> *arc_map = nullptr) { | ||
k2::ArcSort(fsa, arc_map == nullptr ? nullptr : arc_map->data); | ||
}, | ||
"in-place version of ArcSorter", py::arg("fsa"), | ||
py::arg("arc_map") = (k2::Array1<int32_t *> *)nullptr); | ||
} | ||
|
||
void PybindFsaAlgo(py::module &m) { PyBindArcSort(m); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// k2/python/csrc/fsa_algo.h | ||
|
||
// Copyright (c) 2020 Xiaomi Corporation (author: Haowen Qiu) | ||
|
||
// See ../../../LICENSE for clarification regarding multiple authors | ||
|
||
#ifndef K2_PYTHON_CSRC_FSA_ALGO_H_ | ||
#define K2_PYTHON_CSRC_FSA_ALGO_H_ | ||
|
||
#include "k2/python/csrc/k2.h" | ||
|
||
void PybindFsaAlgo(py::module &m); | ||
|
||
#endif // K2_PYTHON_CSRC_FSA_ALGO_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from _k2 import Arc | ||
from _k2 import IntArray2Size | ||
from .array import * | ||
from .fsa import * | ||
from .fsa_algo import * | ||
from .fsa_util import str_to_fsa |
Oops, something went wrong.