Browse Source

2024.5.16 测试整体构建

master
Administrator 1 year ago
parent
commit
b727d81c15
7 changed files with 1 additions and 603 deletions
  1. +1
    -1
      frontend/feature_pipeline.h
  2. +0
    -23
      patch/openfst/src/CMakeLists.txt
  3. +0
    -67
      patch/openfst/src/extensions/special/CMakeLists.txt
  4. +0
    -219
      patch/openfst/src/include/fst/flags.h
  5. +0
    -78
      patch/openfst/src/include/fst/log.h
  6. +0
    -160
      patch/openfst/src/lib/flags.cc
  7. +0
    -55
      patch/openfst/src/test/CMakeLists.txt

+ 1
- 1
frontend/feature_pipeline.h

@ -73,7 +73,7 @@ struct FeaturePipelineConfig {
}
void Info() const {
google::LOG(INFO) << "feature pipeline config"
fst::LOG(INFO) << "feature pipeline config"
<< " num_bins " << num_bins << " frame_length " << frame_length
<< " frame_shift " << frame_shift << " low_freq " << low_freq
<< " preemphasis " << pre_emphasis << " log_floor " << log_floor

+ 0
- 23
patch/openfst/src/CMakeLists.txt

@ -1,23 +0,0 @@
#-DHAVE_CONFIG_H -I./../include -fno-exceptions -funsigned-char -std=c++11 -MT symbol-table.lo -MD -MP -MF .deps/symbol-table.Tpo -c symbol-table.cc -fno-common -DPIC -o .libs/symbol-table.o
include_directories(./include/)
install(DIRECTORY include/ DESTINATION include/
FILES_MATCHING PATTERN "*.h")
add_subdirectory(lib)
if(HAVE_SCRIPT)
add_subdirectory(script)
endif(HAVE_SCRIPT)
if(HAVE_BIN)
add_subdirectory(bin)
endif(HAVE_BIN)
add_subdirectory(extensions)
if(BUILD_TESTING)
enable_testing()
add_subdirectory(test)
endif(BUILD_TESTING)

+ 0
- 67
patch/openfst/src/extensions/special/CMakeLists.txt

@ -1,67 +0,0 @@
file(GLOB HEADER_FILES ../../include/fst/extensions/special/*.h)
message(STATUS "${HEADER_FILES}")
if(HAVE_BIN)
add_executable(fstspecial-bin
../../bin/fstconvert.cc
../../bin/fstconvert-main.cc
phi-fst.cc
rho-fst.cc
sigma-fst.cc
)
set_target_properties(fstspecial-bin PROPERTIES
FOLDER special/bin
OUTPUT_NAME fstspecial
)
target_link_libraries(fstspecial-bin
fstscript
fst
${CMAKE_DL_LIBS}
)
endif(HAVE_BIN)
add_library(fstspecial
phi-fst.cc
rho-fst.cc
sigma-fst.cc
${HEADER_FILES}
)
set_target_properties(fstspecial PROPERTIES
SOVERSION "${SOVERSION}"
FOLDER special
)
target_link_libraries(fstspecial
fst
)
set(FST_SPECIAL_INSTALL_TARGETS fstspecial)
if(HAVE_BIN)
list(APPEND FST_SPECIAL_INSTALL_TARGETS fstspecial-bin)
endif()
install(TARGETS ${FST_SPECIAL_INSTALL_TARGETS}
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
)
function (add_module _name)
add_library(${ARGV})
if (TARGET ${_name})
target_link_libraries(${_name} fst)
set_target_properties(${_name}
PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS true
FOLDER special/modules
)
endif()
install(TARGETS ${_name} LIBRARY DESTINATION lib/fst)
endfunction()
add_module(phi-fst MODULE phi-fst.cc)
add_module(rho-fst MODULE rho-fst.cc)
add_module(sigma-fst MODULE sigma-fst.cc)

+ 0
- 219
patch/openfst/src/include/fst/flags.h

@ -1,219 +0,0 @@
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// See www.openfst.org for extensive documentation on this weighted
// finite-state transducer library.
//
// Google-style flag handling declarations and inline definitions.
#ifndef FST_LIB_FLAGS_H_
#define FST_LIB_FLAGS_H_
#include <cstdlib>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <fst/lock.h>
#include <fst/types.h>
#include "gflags/gflags.h"
#include "glog/logging.h"
using std::string;
// FLAGS USAGE:
//
// Definition example:
//
// DEFINE_int32(length, 0, "length");
//
// This defines variable FLAGS_length, initialized to 0.
//
// Declaration example:
//
// DECLARE_int32(length);
//
// SET_FLAGS() can be used to set flags from the command line
// using, for example, '--length=2'.
//
// ShowUsage() can be used to print out command and flag usage.
// #define DECLARE_bool(name) extern bool FLAGS_ ## name
// #define DECLARE_string(name) extern string FLAGS_ ## name
// #define DECLARE_int32(name) extern int32 FLAGS_ ## name
// #define DECLARE_int64(name) extern int64 FLAGS_ ## name
// #define DECLARE_double(name) extern double FLAGS_ ## name
template <typename T>
struct FlagDescription {
FlagDescription(T* addr, const char* doc, const char* type, const char* file,
const T val)
: address(addr),
doc_string(doc),
type_name(type),
file_name(file),
default_value(val) {}
T* address;
const char* doc_string;
const char* type_name;
const char* file_name;
const T default_value;
};
template <typename T>
class FlagRegister {
public:
static FlagRegister<T>* GetRegister() {
static auto reg = new FlagRegister<T>;
return reg;
}
const FlagDescription<T>& GetFlagDescription(const string& name) const {
fst::MutexLock l(&flag_lock_);
auto it = flag_table_.find(name);
return it != flag_table_.end() ? it->second : 0;
}
void SetDescription(const string& name, const FlagDescription<T>& desc) {
fst::MutexLock l(&flag_lock_);
flag_table_.insert(make_pair(name, desc));
}
bool SetFlag(const string& val, bool* address) const {
if (val == "true" || val == "1" || val.empty()) {
*address = true;
return true;
} else if (val == "false" || val == "0") {
*address = false;
return true;
} else {
return false;
}
}
bool SetFlag(const string& val, string* address) const {
*address = val;
return true;
}
bool SetFlag(const string& val, int32* address) const {
char* p = 0;
*address = strtol(val.c_str(), &p, 0);
return !val.empty() && *p == '\0';
}
bool SetFlag(const string& val, int64* address) const {
char* p = 0;
*address = strtoll(val.c_str(), &p, 0);
return !val.empty() && *p == '\0';
}
bool SetFlag(const string& val, double* address) const {
char* p = 0;
*address = strtod(val.c_str(), &p);
return !val.empty() && *p == '\0';
}
bool SetFlag(const string& arg, const string& val) const {
for (typename std::map<string, FlagDescription<T>>::const_iterator it =
flag_table_.begin();
it != flag_table_.end(); ++it) {
const string& name = it->first;
const FlagDescription<T>& desc = it->second;
if (arg == name) return SetFlag(val, desc.address);
}
return false;
}
void GetUsage(std::set<std::pair<string, string>>* usage_set) const {
for (auto it = flag_table_.begin(); it != flag_table_.end(); ++it) {
const string& name = it->first;
const FlagDescription<T>& desc = it->second;
string usage = " --" + name;
usage += ": type = ";
usage += desc.type_name;
usage += ", default = ";
usage += GetDefault(desc.default_value) + "\n ";
usage += desc.doc_string;
usage_set->insert(make_pair(desc.file_name, usage));
}
}
private:
string GetDefault(bool default_value) const {
return default_value ? "true" : "false";
}
string GetDefault(const string& default_value) const {
return "\"" + default_value + "\"";
}
template <class V>
string GetDefault(const V& default_value) const {
std::ostringstream strm;
strm << default_value;
return strm.str();
}
mutable fst::Mutex flag_lock_; // Multithreading lock.
std::map<string, FlagDescription<T>> flag_table_;
};
template <typename T>
class FlagRegisterer {
public:
FlagRegisterer(const string& name, const FlagDescription<T>& desc) {
auto registr = FlagRegister<T>::GetRegister();
registr->SetDescription(name, desc);
}
private:
FlagRegisterer(const FlagRegisterer&) = delete;
FlagRegisterer& operator=(const FlagRegisterer&) = delete;
};
#define DEFINE_VAR(type, name, value, doc) \
type FLAGS_##name = value; \
static FlagRegisterer<type> name##_flags_registerer( \
#name, \
FlagDescription<type>(&FLAGS_##name, doc, #type, __FILE__, value))
// #define DEFINE_bool(name, value, doc) DEFINE_VAR(bool, name, value, doc)
// #define DEFINE_string(name, value, doc) \
// DEFINE_VAR(string, name, value, doc)
// #define DEFINE_int32(name, value, doc) DEFINE_VAR(int32, name, value, doc)
// #define DEFINE_int64(name, value, doc) DEFINE_VAR(int64, name, value, doc)
// #define DEFINE_double(name, value, doc) DEFINE_VAR(double, name, value, doc)
// Temporary directory.
DECLARE_string(tmpdir);
void SetFlags(const char* usage, int* argc, char*** argv, bool remove_flags,
const char* src = "");
#define SET_FLAGS(usage, argc, argv, rmflags) \
gflags::ParseCommandLineFlags(argc, argv, true)
// SetFlags(usage, argc, argv, rmflags, __FILE__)
// Deprecated; for backward compatibility.
inline void InitFst(const char* usage, int* argc, char*** argv, bool rmflags) {
return SetFlags(usage, argc, argv, rmflags);
}
void ShowUsage(bool long_usage = true);
#endif // FST_LIB_FLAGS_H_

+ 0
- 78
patch/openfst/src/include/fst/log.h

@ -1,78 +0,0 @@
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// See www.openfst.org for extensive documentation on this weighted
// finite-state transducer library.
//
// Google-style logging declarations and inline definitions.
#ifndef FST_LIB_LOG_H_
#define FST_LIB_LOG_H_
#include <cassert>
#include <iostream>
#include <string>
#include <fst/flags.h>
#include <fst/types.h>
using std::string;
DECLARE_int32(v);
class LogMessage {
public:
LogMessage(const string& type) : fatal_(type == "FATAL") {
std::cerr << type << ": ";
}
~LogMessage() {
std::cerr << std::endl;
if (fatal_) exit(1);
}
std::ostream& stream() { return std::cerr; }
private:
bool fatal_;
};
// #define LOG(type) LogMessage(#type).stream()
// #define VLOG(level) if ((level) <= FLAGS_v) LOG(INFO)
// Checks
inline void FstCheck(bool x, const char* expr, const char* file, int line) {
if (!x) {
LOG(FATAL) << "Check failed: \"" << expr << "\" file: " << file
<< " line: " << line;
}
}
// #define CHECK(x) FstCheck(static_cast<bool>(x), #x, __FILE__, __LINE__)
// #define CHECK_EQ(x, y) CHECK((x) == (y))
// #define CHECK_LT(x, y) CHECK((x) < (y))
// #define CHECK_GT(x, y) CHECK((x) > (y))
// #define CHECK_LE(x, y) CHECK((x) <= (y))
// #define CHECK_GE(x, y) CHECK((x) >= (y))
// #define CHECK_NE(x, y) CHECK((x) != (y))
// Debug checks
// #define DCHECK(x) assert(x)
// #define DCHECK_EQ(x, y) DCHECK((x) == (y))
// #define DCHECK_LT(x, y) DCHECK((x) < (y))
// #define DCHECK_GT(x, y) DCHECK((x) > (y))
// #define DCHECK_LE(x, y) DCHECK((x) <= (y))
// #define DCHECK_GE(x, y) DCHECK((x) >= (y))
// #define DCHECK_NE(x, y) DCHECK((x) != (y))
// Ports
#define ATTRIBUTE_DEPRECATED __attribute__((deprecated))
#endif // FST_LIB_LOG_H_

+ 0
- 160
patch/openfst/src/lib/flags.cc

@ -1,160 +0,0 @@
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Google-style flag handling definitions.
#include <cstring>
#if _MSC_VER
#include <fcntl.h>
#include <io.h>
#endif
#include <fst/compat.h>
#include <fst/flags.h>
static const char* private_tmpdir = getenv("TMPDIR");
// DEFINE_int32(v, 0, "verbosity level");
// DEFINE_bool(help, false, "show usage information");
// DEFINE_bool(helpshort, false, "show brief usage information");
#ifndef _MSC_VER
DEFINE_string(tmpdir, private_tmpdir ? private_tmpdir : "/tmp",
"temporary directory");
#else
DEFINE_string(tmpdir, private_tmpdir ? private_tmpdir : getenv("TEMP"),
"temporary directory");
#endif // !_MSC_VER
using namespace std;
static string flag_usage;
static string prog_src;
// Sets prog_src to src.
static void SetProgSrc(const char* src) {
prog_src = src;
#if _MSC_VER
// This common code is invoked by all FST binaries, and only by them. Switch
// stdin and stdout into "binary" mode, so that 0x0A won't be translated into
// a 0x0D 0x0A byte pair in a pipe or a shell redirect. Other streams are
// already using ios::binary where binary files are read or written.
// Kudos to @daanzu for the suggested fix.
// https://github.com/kkm000/openfst/issues/20
// https://github.com/kkm000/openfst/pull/23
// https://github.com/kkm000/openfst/pull/32
_setmode(_fileno(stdin), O_BINARY);
_setmode(_fileno(stdout), O_BINARY);
#endif
// Remove "-main" in src filename. Flags are defined in fstx.cc but SetFlags()
// is called in fstx-main.cc, which results in a filename mismatch in
// ShowUsageRestrict() below.
static constexpr char kMainSuffix[] = "-main.cc";
const int prefix_length = prog_src.size() - strlen(kMainSuffix);
if (prefix_length > 0 && prog_src.substr(prefix_length) == kMainSuffix) {
prog_src.erase(prefix_length, strlen("-main"));
}
}
void SetFlags(const char* usage, int* argc, char*** argv, bool remove_flags,
const char* src) {
flag_usage = usage;
SetProgSrc(src);
int index = 1;
for (; index < *argc; ++index) {
string argval = (*argv)[index];
if (argval[0] != '-' || argval == "-") break;
while (argval[0] == '-') argval = argval.substr(1); // Removes initial '-'.
string arg = argval;
string val = "";
// Splits argval (arg=val) into arg and val.
auto pos = argval.find("=");
if (pos != string::npos) {
arg = argval.substr(0, pos);
val = argval.substr(pos + 1);
}
auto bool_register = FlagRegister<bool>::GetRegister();
if (bool_register->SetFlag(arg, val)) continue;
auto string_register = FlagRegister<string>::GetRegister();
if (string_register->SetFlag(arg, val)) continue;
auto int32_register = FlagRegister<int32>::GetRegister();
if (int32_register->SetFlag(arg, val)) continue;
auto int64_register = FlagRegister<int64>::GetRegister();
if (int64_register->SetFlag(arg, val)) continue;
auto double_register = FlagRegister<double>::GetRegister();
if (double_register->SetFlag(arg, val)) continue;
LOG(FATAL) << "SetFlags: Bad option: " << (*argv)[index];
}
if (remove_flags) {
for (auto i = 0; i < *argc - index; ++i) {
(*argv)[i + 1] = (*argv)[i + index];
}
*argc -= index - 1;
}
// if (FLAGS_help) {
// ShowUsage(true);
// exit(1);
// }
// if (FLAGS_helpshort) {
// ShowUsage(false);
// exit(1);
// }
}
// If flag is defined in file 'src' and 'in_src' true or is not
// defined in file 'src' and 'in_src' is false, then print usage.
static void ShowUsageRestrict(const std::set<pair<string, string>>& usage_set,
const string& src, bool in_src, bool show_file) {
string old_file;
bool file_out = false;
bool usage_out = false;
for (const auto& pair : usage_set) {
const auto& file = pair.first;
const auto& usage = pair.second;
bool match = file == src;
if ((match && !in_src) || (!match && in_src)) continue;
if (file != old_file) {
if (show_file) {
if (file_out) cout << "\n";
cout << "Flags from: " << file << "\n";
file_out = true;
}
old_file = file;
}
cout << usage << "\n";
usage_out = true;
}
if (usage_out) cout << "\n";
}
void ShowUsage(bool long_usage) {
std::set<pair<string, string>> usage_set;
cout << flag_usage << "\n";
auto bool_register = FlagRegister<bool>::GetRegister();
bool_register->GetUsage(&usage_set);
auto string_register = FlagRegister<string>::GetRegister();
string_register->GetUsage(&usage_set);
auto int32_register = FlagRegister<int32>::GetRegister();
int32_register->GetUsage(&usage_set);
auto int64_register = FlagRegister<int64>::GetRegister();
int64_register->GetUsage(&usage_set);
auto double_register = FlagRegister<double>::GetRegister();
double_register->GetUsage(&usage_set);
if (!prog_src.empty()) {
cout << "PROGRAM FLAGS:\n\n";
ShowUsageRestrict(usage_set, prog_src, true, false);
}
if (!long_usage) return;
if (!prog_src.empty()) cout << "LIBRARY FLAGS:\n\n";
ShowUsageRestrict(usage_set, prog_src, false, true);
}

+ 0
- 55
patch/openfst/src/test/CMakeLists.txt

@ -1,55 +0,0 @@
add_executable(fst_test
fst_test.cc
../include/fst/test/fst_test.h
)
target_link_libraries(fst_test fst ${CMAKE_DL_LIBS})
set_target_properties(fst_test PROPERTIES FOLDER test)
add_test(NAME fst_test-test COMMAND fst_test)
add_executable(weight_test
weight_test.cc
../include/fst/test/weight-tester.h
)
target_link_libraries(weight_test fst ${CMAKE_DL_LIBS})
set_target_properties(weight_test PROPERTIES FOLDER test)
add_test(NAME weight_test-test COMMAND weight_test)
add_executable(algo_test_log algo_test.cc ../include/fst/test/algo_test.h ../include/fst/test/rand-fst.h)
target_link_libraries(algo_test_log fst ${CMAKE_DL_LIBS})
target_compile_definitions(algo_test_log
PRIVATE TEST_LOG=1)
set_target_properties(algo_test_log PROPERTIES FOLDER test)
add_test(NAME algo_test_log-test COMMAND algo_test_log)
add_executable(algo_test_tropical algo_test.cc ../include/fst/test/algo_test.h ../include/fst/test/rand-fst.h)
target_link_libraries(algo_test_tropical fst ${CMAKE_DL_LIBS})
target_compile_definitions(algo_test_tropical
PRIVATE TEST_TROPICAL=1)
set_target_properties(algo_test_tropical PROPERTIES FOLDER test)
add_test(NAME algo_test_tropical-test COMMAND algo_test_tropical)
add_executable(algo_test_minmax algo_test.cc ../include/fst/test/algo_test.h ../include/fst/test/rand-fst.h)
target_link_libraries(algo_test_minmax fst ${CMAKE_DL_LIBS})
target_compile_definitions(algo_test_minmax
PRIVATE TEST_MINMAX=1)
set_target_properties(algo_test_minmax PROPERTIES FOLDER test)
add_test(NAME algo_test_minmax-test COMMAND algo_test_minmax)
add_executable(algo_test_lexicographic algo_test.cc ../include/fst/test/algo_test.h ../include/fst/test/rand-fst.h)
target_link_libraries(algo_test_lexicographic fst ${CMAKE_DL_LIBS})
target_compile_definitions(algo_test_lexicographic
PRIVATE TEST_LEXICOGRAPHIC=1)
set_target_properties(algo_test_lexicographic PROPERTIES FOLDER test)
add_test(NAME algo_test_lexicographic-test COMMAND algo_test_lexicographic)
add_executable(algo_test_power algo_test.cc ../include/fst/test/algo_test.h ../include/fst/test/rand-fst.h)
target_link_libraries(algo_test_power fst ${CMAKE_DL_LIBS})
target_compile_definitions(algo_test_power
PRIVATE TEST_POWER=1)
set_target_properties(algo_test_power PROPERTIES FOLDER test)
add_test(NAME algo_test_power-test COMMAND algo_test_power)

Loading…
Cancel
Save