aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorArik Poznanski <arikpoz@users.noreply.github.com>2023-04-17 17:41:53 +0300
committerGitHub <noreply@github.com>2023-04-17 17:41:53 +0300
commitefd05648c88a0923a55f56e7ce1b0f9c33410afb (patch)
treeab3ba2322a5368c73f208a9fb110e01bb7db3721 /tests
parenteb17a026fd23d1c1b612fa4600f7f5c58e501a28 (diff)
llama : well-defined static initialization of complex objects (#927)
* Replaced static initialization of complex objects with a initialization on first use. This prevents an undefined behavior on program run, for example, crash in Release build, works in Debug build * replaced use of auto with exact type to avoid using -std=c++14 * Made the assessors functions for static maps be static const
Diffstat (limited to 'tests')
-rw-r--r--tests/test-tokenizer-0.cpp20
1 files changed, 12 insertions, 8 deletions
diff --git a/tests/test-tokenizer-0.cpp b/tests/test-tokenizer-0.cpp
index 55b086d..b089845 100644
--- a/tests/test-tokenizer-0.cpp
+++ b/tests/test-tokenizer-0.cpp
@@ -5,13 +5,17 @@
#include <map>
#include <vector>
-static const std::map<std::string, std::vector<llama_token>> k_tests = {
- { "Hello World", { 1, 10994, 2787, }, },
- { " Hello World", { 1, 15043, 2787, }, },
- { " Hello World!", { 1, 15043, 2787, 29991, }, },
- { " this is 🦙.cpp", { 1, 445, 338, 29871, 243, 162, 169, 156, 29889, 8223, }, },
- { "w048 7tuijk dsdfhu", { 1, 29893, 29900, 29946, 29947, 29871, 29955, 9161, 13535, 18031, 2176, 6905, }, },
- { "нещо на Български", { 1, 821, 4851, 665, 1386, 29713, 1305, }, },
+static const std::map<std::string, std::vector<llama_token>> & k_tests()
+{
+ static std::map<std::string, std::vector<llama_token>> _k_tests = {
+ { "Hello World", { 1, 10994, 2787, }, },
+ { " Hello World", { 1, 15043, 2787, }, },
+ { " Hello World!", { 1, 15043, 2787, 29991, }, },
+ { " this is 🦙.cpp", { 1, 445, 338, 29871, 243, 162, 169, 156, 29889, 8223, }, },
+ { "w048 7tuijk dsdfhu", { 1, 29893, 29900, 29946, 29947, 29871, 29955, 9161, 13535, 18031, 2176, 6905, }, },
+ { "нещо на Български", { 1, 821, 4851, 665, 1386, 29713, 1305, }, },
+ };
+ return _k_tests;
};
int main(int argc, char **argv) {
@@ -47,7 +51,7 @@ int main(int argc, char **argv) {
return 2;
}
- for (const auto & test_kv : k_tests) {
+ for (const auto & test_kv : k_tests()) {
std::vector<llama_token> res(test_kv.first.size());
const int n = llama_tokenize(ctx, test_kv.first.c_str(), res.data(), res.size(), true);
res.resize(n);