-
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.
wrap properties and some fsa algorithms to Python (#70)
* wrap properties and some fsa algorithms to Python * fix comment issues
- Loading branch information
Showing
22 changed files
with
907 additions
and
36 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
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
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ pybind11_add_module(_k2 | |
fsa_algo.cc | ||
fsa_util.cc | ||
k2.cc | ||
properties.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// k2/python/csrc/properties.cc | ||
|
||
// Copyright (c) 2020 Xiaomi Corporation (author: Haowen Qiu) | ||
|
||
// See ../../../LICENSE for clarification regarding multiple authors | ||
|
||
#include "k2/python/csrc/properties.h" | ||
|
||
#include <vector> | ||
|
||
#include "k2/csrc/array.h" | ||
#include "k2/csrc/fsa.h" | ||
#include "k2/csrc/properties.h" | ||
#include "k2/python/csrc/array.h" | ||
|
||
// We would never pass `order` parameter to k2::IsAcyclic in Python code. | ||
// We can make it accept `None` with `std::optional` in pybind11, but | ||
// that will require C++17, so we here choose to write a version without | ||
// `order`. | ||
static bool IsAcyclic(const k2::Fsa &fsa) { | ||
return k2::IsAcyclic(fsa /*, std::vector<int32_t>* order = nullptr*/); | ||
} | ||
|
||
void PybindProperties(py::module &m) { | ||
m.def("_is_valid", &k2::IsValid, py::arg("fsa")); | ||
m.def("_is_top_sorted", &k2::IsTopSorted, py::arg("fsa")); | ||
m.def("_is_arc_sorted", &k2::IsArcSorted, py::arg("fsa")); | ||
m.def("_has_self_loops", &k2::HasSelfLoops, py::arg("fsa")); | ||
m.def("_is_acyclic", &IsAcyclic, py::arg("fsa")); | ||
m.def("_is_deterministic", &k2::IsDeterministic, py::arg("fsa")); | ||
m.def("_is_epsilon_free", &k2::IsEpsilonFree, py::arg("fsa")); | ||
m.def("_is_connected", &k2::IsConnected, py::arg("fsa")); | ||
m.def("_is_empty", &k2::IsEmpty, py::arg("fsa")); | ||
} |
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/properties.h | ||
|
||
// Copyright (c) 2020 Xiaomi Corporation (author: Haowen Qiu) | ||
|
||
// See ../../../LICENSE for clarification regarding multiple authors | ||
|
||
#ifndef K2_PYTHON_CSRC_PROPERTIES_H_ | ||
#define K2_PYTHON_CSRC_PROPERTIES_H_ | ||
|
||
#include "k2/python/csrc/k2.h" | ||
|
||
void PybindProperties(py::module &m); | ||
|
||
#endif // K2_PYTHON_CSRC_PROPERTIES_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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
from .fsa import * | ||
from .fsa_algo import * | ||
from .fsa_util import str_to_fsa | ||
from .properties import * |
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
Oops, something went wrong.