Skip to content

Commit 677dc49

Browse files
committed
[refactor] C splits into C++
Auxiliary function to convert a list of C strings to a vector of C++ strings.
1 parent bebc5ca commit 677dc49

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/llama.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,18 +248,26 @@ struct llama_model * llama_model_load_from_file(
248248
return llama_model_load_from_file_impl(path_model, splits, params);
249249
}
250250

251-
struct llama_model * llama_model_load_from_splits(
252-
const char ** paths,
253-
size_t n_paths,
254-
struct llama_model_params params) {
251+
namespace {
252+
std::vector<std::string> splits_from_c_paths(const char ** paths, size_t n_paths) {
255253
std::vector<std::string> splits;
256254
if (n_paths == 0) {
257255
LLAMA_LOG_ERROR("%s: list of splits is empty\n", __func__);
258-
return nullptr;
256+
return splits;
259257
}
260258
for (size_t i = 0; i < n_paths; ++i) {
261259
splits.push_back(paths[i]);
262260
}
261+
return splits;
262+
}
263+
} // namespace
264+
265+
struct llama_model * llama_model_load_from_splits(const char ** paths, size_t n_paths,
266+
struct llama_model_params params) {
267+
std::vector<std::string> splits = splits_from_c_paths(paths, n_paths);
268+
if (splits.empty()) {
269+
return nullptr;
270+
}
263271
return llama_model_load_from_file_impl(splits.front(), splits, params);
264272
}
265273

0 commit comments

Comments
 (0)