From ad2522b319c4a1be817c9dea511415934aeaa868 Mon Sep 17 00:00:00 2001 From: Concedo <39025047+LostRuins@users.noreply.github.com> Date: Mon, 14 Apr 2025 23:05:36 +0800 Subject: [PATCH] str splitter --- otherarch/utils.cpp | 17 +++++++++++++++++ otherarch/utils.h | 2 ++ 2 files changed, 19 insertions(+) diff --git a/otherarch/utils.cpp b/otherarch/utils.cpp index 29f9e698f..897b5243a 100644 --- a/otherarch/utils.cpp +++ b/otherarch/utils.cpp @@ -542,4 +542,21 @@ kcpp_embd_batch::kcpp_embd_batch(std::vector & tokens, int32_t npas } } batch.logits[n_tokens - 1] = true; +} + +std::vector split_string(const std::string& input, const std::string& separator) { + std::vector result; + size_t start = 0; + size_t end = input.find(separator); + + while (end != std::string::npos) { + result.push_back(input.substr(start, end - start)); + start = end + separator.length(); + end = input.find(separator, start); + } + + // Add the remaining part after the last separator + result.push_back(input.substr(start)); + + return result; } \ No newline at end of file diff --git a/otherarch/utils.h b/otherarch/utils.h index 78012fd6e..83aa7648f 100644 --- a/otherarch/utils.h +++ b/otherarch/utils.h @@ -65,6 +65,8 @@ std::vector resample_wav(const std::vector& input, uint32_t input_ int32_t kcpp_quick_sample(float * logits, const int n_logits, const std::vector & last_n_tokens, float rep_pen, float top_p, int top_k, float temp, std::mt19937 & rng); +std::vector split_string(const std::string& input, const std::string& separator); + struct kcpp_embd_batch { //duplcated from llava_embd_batch std::vector pos; std::vector n_seq_id;