Replace size check with empty

This commit is contained in:
Michael Klimenko 2024-01-27 21:23:27 +01:00
parent c3fe181c44
commit e41d94972c
7 changed files with 19 additions and 19 deletions

View file

@ -850,7 +850,7 @@ size_t tokenize_file(
utf8_nunits.resize(buf.size());
mark_utf8_units(buf.data(), utf8_units.data(), utf8_nunits.data(), buf.size());
if (sample_start.size() == 0) {
if (sample_start.empty()) {
// tokenize all data at once
out_tokens.resize(buf.size() + n_max_tokens_overhead);
@ -898,7 +898,7 @@ size_t tokenize_file(
const size_t search_start = sample_begin + sample_start.size();
sample_begin = data_str.find(sample_start, search_start);
}
if (out_samples_begin.size() == 0) {
if (out_samples_begin.empty()) {
printf("%s: warning: sample start pattern '%s' not found. inserting single sample at data begin\n",
__func__, sample_start.c_str());
out_samples_begin.push_back(0);

View file

@ -376,7 +376,7 @@ static void export_lora(struct export_lora_params * params) {
loras.push_back(lora);
}
}
if (loras.size() == 0) {
if (loras.empty()) {
fprintf(stderr, "warning: no lora adapters will be applied.\n");
}

View file

@ -1835,7 +1835,7 @@ int main(int argc, char ** argv) {
if (params.common.force_reshuffle) {
printf("%s: forced reshuffling of data. restarting with newly shuffled epoch.\n", __func__);
}
if ((train->shuffle_rng_state_current == "") || changed_train_data || params.common.force_reshuffle) {
if ((train->shuffle_rng_state_current.empty()) || changed_train_data || params.common.force_reshuffle) {
train->shuffle_rng_state_current = mt19937_seed_to_state(params.common.seed);
train->shuffle_sample_count = train_samples_size.size();
train->shuffle_next_sample = 0;

View file

@ -6941,7 +6941,7 @@ inline ContentProviderWithoutLength ClientImpl::get_multipart_content_provider(
// state between successive calls
return [&, cur_item, cur_start](size_t offset,
DataSink &sink) mutable -> bool {
if (!offset && items.size()) {
if (!offset && !items.empty()) {
sink.os << detail::serialize_multipart_formdata(items, boundary, false);
return true;
} else if (cur_item < provider_items.size()) {

View file

@ -649,7 +649,7 @@ struct llama_server_context
}
// process prompt
// example: system prompt [img-102] user [img-103] describe [img-134] -> [{id: 102, prefix: 'system prompt '}, {id: 103, prefix: ' user '}, {id: 134, prefix: ' describe '}]}
if (slot->images.size() > 0 && !slot->prompt.is_array())
if (!slot->images.empty() && !slot->prompt.is_array())
{
std::string prompt = slot->prompt.get<std::string>();
size_t pos = 0, begin_prefix = 0;
@ -758,7 +758,7 @@ struct llama_server_context
name_user = sys_props.value("anti_prompt", "");
name_assistant = sys_props.value("assistant_name", "");
if (slots.size() > 0)
if (!slots.empty())
{
notify_system_prompt_changed();
}
@ -944,7 +944,7 @@ struct llama_server_context
img.request_encode_image = false;
}
return slot.images.size() > 0;
return !slot.images.empty();
}
void send_error(task_server& task, const std::string &error)
@ -1794,7 +1794,7 @@ static void server_params_parse(int argc, char **argv, server_params &sparams,
}
std::string key;
while (std::getline(key_file, key)) {
if (key.size() > 0) {
if (!key.empty()) {
sparams.api_keys.push_back(key);
}
}

View file

@ -1200,7 +1200,7 @@ int main(int argc, char ** argv) {
if (params.common.force_reshuffle) {
printf("%s: forced reshuffling of data. restarting with newly shuffled epoch.\n", __func__);
}
if ((train->shuffle_rng_state_current == "") || changed_train_data || params.common.force_reshuffle) {
if ((train->shuffle_rng_state_current.empty()) || changed_train_data || params.common.force_reshuffle) {
train->shuffle_rng_state_current = mt19937_seed_to_state(params.common.seed);
train->shuffle_sample_count = train_samples_size.size();
train->shuffle_next_sample = 0;

View file

@ -3015,7 +3015,7 @@ static void llm_load_vocab(
for (int i = 0; i < n_merges; i++) {
const std::string word = gguf_get_arr_str(ctx, merges_keyidx, i);
GGML_ASSERT(codepoints_from_utf8(word).size() > 0);
GGML_ASSERT(!codepoints_from_utf8(word).empty());
std::string first;
std::string second;
@ -3050,7 +3050,7 @@ static void llm_load_vocab(
for (uint32_t i = 0; i < n_vocab; i++) {
std::string word = gguf_get_arr_str(ctx, token_idx, i);
GGML_ASSERT(codepoints_from_utf8(word).size() > 0);
GGML_ASSERT(!codepoints_from_utf8(word).empty());
vocab.token_to_id[word] = i;
@ -7190,7 +7190,7 @@ private:
split_condition = true;
}
if (split_condition) {
if (token.size()) {
if (!token.empty()) {
bpe_words.emplace_back(token); // push previous content as token
}
token = utf_char + utf_char_next;
@ -7211,7 +7211,7 @@ private:
}
if (split_condition) {
// current token + next token can be defined
if (token.size()) {
if (!token.empty()) {
bpe_words.emplace_back(token); // push previous content as token
}
token = utf_char + utf_char_next + utf_char_next_next;
@ -7223,17 +7223,17 @@ private:
}
if (!split_condition && !collecting) {
if (codepoint_type(utf_char) == CODEPOINT_TYPE_LETTER || (!token.size() && utf_char == " " && codepoint_type(utf_char_next) == CODEPOINT_TYPE_LETTER)) {
if (codepoint_type(utf_char) == CODEPOINT_TYPE_LETTER || (token.empty() && utf_char == " " && codepoint_type(utf_char_next) == CODEPOINT_TYPE_LETTER)) {
collecting_letter = true;
collecting = true;
}
else if (codepoint_type(utf_char) == CODEPOINT_TYPE_DIGIT || (!token.size() && utf_char == " " && codepoint_type(utf_char_next) == CODEPOINT_TYPE_DIGIT)) {
else if (codepoint_type(utf_char) == CODEPOINT_TYPE_DIGIT || (token.empty() && utf_char == " " && codepoint_type(utf_char_next) == CODEPOINT_TYPE_DIGIT)) {
collecting_numeric = true;
collecting = true;
}
else if (
((codepoint_type(utf_char) != CODEPOINT_TYPE_LETTER && codepoint_type(utf_char) != CODEPOINT_TYPE_DIGIT) && (codepoint_type(utf_char) != CODEPOINT_TYPE_WHITESPACE)) ||
(!token.size() && utf_char == " " && codepoint_type(utf_char_next) != CODEPOINT_TYPE_LETTER && codepoint_type(utf_char_next) != CODEPOINT_TYPE_DIGIT && codepoint_type(utf_char_next) != CODEPOINT_TYPE_WHITESPACE)
(token.empty() && utf_char == " " && codepoint_type(utf_char_next) != CODEPOINT_TYPE_LETTER && codepoint_type(utf_char_next) != CODEPOINT_TYPE_DIGIT && codepoint_type(utf_char_next) != CODEPOINT_TYPE_WHITESPACE)
) {
collecting_special = true;
collecting = true;
@ -7261,13 +7261,13 @@ private:
}
}
if (utf_char_next == "") {
if (utf_char_next.empty()) {
split_condition = true; // final
token += utf_char;
}
if (split_condition) {
if (token.size()) {
if (!token.empty()) {
bpe_words.emplace_back(token);
}
token = utf_char;