92 #ifndef FST_SCRIPT_SCRIPT_IMPL_H_ 93 #define FST_SCRIPT_SCRIPT_IMPL_H_ 118 template <
class OperationSignature>
122 GenericOperationRegister<OperationSignature>> {
125 const std::string &arc_type) {
126 return this->GetEntry(std::make_pair(operation_name, arc_type));
131 const std::pair<std::string, std::string> &key)
const final {
133 std::string legal_type(key.second);
135 legal_type.append(
"-arc.so");
147 template <
class Args>
161 #define REGISTER_FST_OPERATION(Op, Arc, ArgPack) \ 162 static fst::script::Operation<ArgPack>::Registerer \ 163 arc_dispatched_operation_##ArgPack##Op##Arc##_registerer \ 164 ({#Op, Arc::Type()}, Op<Arc>) 167 #define REGISTER_FST_OPERATION_3ARCS(Op, ArgPack) \ 168 REGISTER_FST_OPERATION(Op, StdArc, ArgPack); \ 169 REGISTER_FST_OPERATION(Op, LogArc, ArgPack); \ 170 REGISTER_FST_OPERATION(Op, Log64Arc, ArgPack) 173 template <
class OpReg>
174 void Apply(
const std::string &op_name,
const std::string &arc_type,
175 typename OpReg::ArgPack *args) {
177 OpReg::Register::GetRegister()->GetOperation(op_name, arc_type);
179 FSTERROR() << op_name <<
": No operation found on arc type " << arc_type;
190 template <
class M,
class N>
192 if (m.ArcType() != n.ArcType()) {
193 FSTERROR() << op_name <<
": Arguments with non-matching arc types " 194 << m.ArcType() <<
" and " << n.ArcType();
201 template <
class Weight>
203 std::vector<Weight> *typed_weights) {
204 typed_weights->clear();
205 typed_weights->reserve(weights.size());
206 for (
const auto &weight : weights) {
207 typed_weights->emplace_back(*weight.GetWeight<Weight>());
212 template <
class Weight>
214 std::vector<WeightClass> *weights) {
216 weights->reserve(typed_weights.size());
217 for (
const auto &typed_weight : typed_weights) {
218 weights->emplace_back(typed_weight);
225 inline std::vector<std::pair<int64_t, const FstClass *>>
BorrowPairs(
226 const std::vector<std::pair<int64_t, std::unique_ptr<const FstClass>>>
228 std::vector<std::pair<int64_t, const FstClass *>> borrowed_pairs;
229 borrowed_pairs.reserve(pairs.size());
230 for (
const auto &pair : pairs) {
231 borrowed_pairs.emplace_back(pair.first, pair.second.get());
233 return borrowed_pairs;
239 #endif // FST_SCRIPT_SCRIPT_IMPL_H_
void CopyWeights(const std::vector< Weight > &typed_weights, std::vector< WeightClass > *weights)
void ConvertToLegalCSymbol(std::string *s)
void Apply(const std::string &op_name, const std::string &arc_type, typename OpReg::ArgPack *args)
bool ArcTypesMatch(const M &m, const N &n, const std::string &op_name)
void(*)(ArgPack *args) OpType
std::vector< std::pair< int64_t, const FstClass * > > BorrowPairs(const std::vector< std::pair< int64_t, std::unique_ptr< const FstClass >>> &pairs)
OperationSignature GetOperation(const std::string &operation_name, const std::string &arc_type)
std::string ConvertKeyToSoFilename(const std::pair< std::string, std::string > &key) const final