其它工具

Posted by lili on

本文的内容主要是翻译文档Other Kaldi utilities。更多本系列文章请点击Kaldi文档解读

目录

本文介绍Kaldi代码里的常见工具函数的概览。

这不包括自成体系的一些工具,比如矩阵库、I/O、logging与错误报告和命令行parsing等。

Text相关的工具

In text-utils.h are various functions for manipulating strings, mostly used in parsing. Important ones include the templated function ConvertStringToInteger(), and the overloaded ConvertStringToReal() functions which are defined for float and double. There is also the SplitStringToIntegers() template whose output is a vector of integers, and SplitStringToVector() which splits a string into a vector of strings.

text-utils.h包含了一些操纵字符串的函数,注意是用于parsing。比较重要的函数包括模板函数ConvertStringToInteger、用于float和double的重载函数ConvertStringToInteger。模板函数SplitStringToIntegers会把字符串表示的整数序列变成vector,SplitStringToVector把字符串split成字符串的vector。

STL工具

In stl-utils.h are templated functions for manipulating STL types. A commonly used one is SortAndUniq(), which sorts and removes duplicates from a vector (of an arbitrary type). The function CopySetToVector() copies the elements of a set into a vector, and is part of a larger category of similar functions that move data between sets, vectors and maps (see a list in stl-utils.h). There are also the hashing-function types VectorHasher (for vectors of integers) and StringHasher (for strings); these are for use with the STL unordered_map and unordered_set templates. Another commonly used function is DeletePointers(), which deletes pointers in a std::vector of pointers, and sets them to NULL.

stl-utils.h包含用于处理STL类型的模板函数。最常用的一个是SortAndUniq,它的作用是对一个vector进行排序和去重。函数CopySetToVector用于把一个集合复制到一个vector,和它类似的还有很多在set、vector和map直接互相转换的函数。同时也包含函数函数类型VectorHasherStringHasher,它们用于STL的unordered_map和unordered_set模板类。另一个常用的函数是DeletePointers,它的作用是删除std::vector里的指针,然后设置为NULL。

数学工具

在kaldi-math.h里,除了用于补充标准math.h里缺失的函数,还包含如下函数:

其它工具

const-integer-set.h包含一个ConstIntegerSet类用于存储整数集合,它可以实现高效的方式存储和查询。不过它要求这个集合构造完成后就不能修改了。这用于决策树的代码里。根据这些整数值的大小,内部可能存储为vector<bool>或者排过序的整数的vector。

timer.h里包括一个用于跨平台的实现计时Timer类。

其它的工具函数和类在simple-io-funcs.hhash-list.h,它们用于特殊场景。其它一些矩阵代码依赖的函数和宏在kaldi-utils.h,这包括字节的swapping、内存对齐和编译时的assertion。