Skip to content

Commit e46a8b5

Browse files
committed
Add spaces around comparison and assignment operators.
1 parent 9bedaf4 commit e46a8b5

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

examples/beam_search/beam_search.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct ostream_beam_view {
3434
};
3535
std::ostream& operator<<(std::ostream& os, ostream_beam_view const & obv) {
3636
os << "p(" << obv.beam_view.p << ") eos(" << std::boolalpha << obv.beam_view.eos << ") tokens(";
37-
for (size_t i=0 ; i<obv.beam_view.n_tokens ; ++i) {
37+
for (size_t i = 0 ; i < obv.beam_view.n_tokens ; ++i) {
3838
os << llama_token_to_str(obv.ctx, obv.beam_view.tokens[i]);
3939
}
4040
return os << ')';
@@ -59,7 +59,7 @@ bool is_at_eos(beam_search_callback_data const & callback_data, llama_token cons
5959
void beam_search_callback(void * callback_data_ptr, llama_beams_state beams_state) {
6060
auto& callback_data = *static_cast<beam_search_callback_data*>(callback_data_ptr);
6161
// Mark beams as EOS as needed.
62-
for (size_t i=0 ; i<beams_state.n_beams ; ++i) {
62+
for (size_t i = 0 ; i < beams_state.n_beams ; ++i) {
6363
llama_beam_view& beam_view = beams_state.beam_views[i];
6464
if (!beam_view.eos && is_at_eos(callback_data, beam_view.tokens, beam_view.n_tokens)) {
6565
beam_view.eos = true;
@@ -76,7 +76,7 @@ void beam_search_callback(void * callback_data_ptr, llama_beams_state beams_stat
7676
fflush(stdout);
7777
#if 1 // DEBUG: print current beams for this iteration
7878
std::cout << "\n\nCurrent beams (last_call=" << beams_state.last_call << "):\n";
79-
for (size_t i=0 ; i < beams_state.n_beams ; ++i) {
79+
for (size_t i = 0 ; i < beams_state.n_beams ; ++i) {
8080
std::cout << "beams["<<i<<"]: " << ostream_beam_view{callback_data.ctx,beams_state.beam_views[i]} << std::endl;
8181
}
8282
#endif

examples/server/server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,7 @@ bool is_at_eos(llama_server_context & server_context, llama_token const * tokens
12221222
void beam_search_callback(void * callback_data, llama_beams_state beams_state) {
12231223
auto & llama = *static_cast<llama_server_context*>(callback_data);
12241224
// Mark beams as EOS as needed.
1225-
for (size_t i=0 ; i<beams_state.n_beams ; ++i) {
1225+
for (size_t i = 0 ; i < beams_state.n_beams ; ++i) {
12261226
llama_beam_view & beam_view = beams_state.beam_views[i];
12271227
if (!beam_view.eos && is_at_eos(llama, beam_view.tokens, beam_view.n_tokens)) {
12281228
beam_view.eos = true;

llama.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4373,12 +4373,12 @@ struct logit_info {
43734373
std::vector<llama_token_data> min_heap; // min-heap by logit
43744374
llama_token const k_min = std::min(static_cast<llama_token>(k), n_vocab);
43754375
min_heap.reserve(k_min);
4376-
for (llama_token token_id=0 ; token_id<k_min ; ++token_id) {
4376+
for (llama_token token_id = 0 ; token_id < k_min ; ++token_id) {
43774377
min_heap.push_back(get_token_data(token_id));
43784378
}
43794379
auto comp = [](llama_token_data const & a, llama_token_data const & b) { return a.logit > b.logit; };
43804380
std::make_heap(min_heap.begin(), min_heap.end(), comp);
4381-
for (llama_token token_id=k_min ; token_id<n_vocab ; ++token_id) {
4381+
for (llama_token token_id = k_min ; token_id < n_vocab ; ++token_id) {
43824382
if (min_heap.front().logit < logits[token_id]) {
43834383
std::pop_heap(min_heap.begin(), min_heap.end(), comp);
43844384
min_heap.back().id = token_id;
@@ -4489,9 +4489,9 @@ struct beam_search {
44894489
// Requires beams is not empty.
44904490
size_t find_common_prefix_length() {
44914491
size_t common_prefix_length = beams[0].tokens.size();
4492-
for (size_t i=1 ; i<beams.size() ; ++i) {
4492+
for (size_t i = 1 ; i < beams.size() ; ++i) {
44934493
common_prefix_length = std::min(common_prefix_length, beams[i].tokens.size());
4494-
for (size_t j=0 ; j<common_prefix_length ; ++j) {
4494+
for (size_t j = 0 ; j < common_prefix_length ; ++j) {
44954495
if (beams[0].tokens[j] != beams[i].tokens[j]) {
44964496
common_prefix_length = j;
44974497
break;
@@ -4504,7 +4504,7 @@ struct beam_search {
45044504
// Construct beams_state to send back to caller via the callback function.
45054505
// Side effect: set common_prefix_length = find_common_prefix_length();
45064506
llama_beams_state get_beams_state(bool const last_call) {
4507-
for (size_t i=0 ; i<beams.size() ; ++i) {
4507+
for (size_t i = 0 ; i < beams.size() ; ++i) {
45084508
beam_views[i] = beams[i].view();
45094509
}
45104510
common_prefix_length = find_common_prefix_length();
@@ -4519,7 +4519,7 @@ struct beam_search {
45194519
void loop(llama_beam_search_callback_fn_t const callback, void * const callback_data) {
45204520
beams.push_back({{}, 1.0f, false}); // Start with one empty beam w/ probability = 1.0 and !eos.
45214521
auto const not_eos = [](llama_beam const & beam) { return !beam.eos; };
4522-
for (int i=0 ; i<n_predict && std::any_of(beams.begin(),beams.end(),not_eos) &&
4522+
for (int i = 0 ; i < n_predict && std::any_of(beams.begin(),beams.end(),not_eos) &&
45234523
!beams[top_beam_index()].eos ; ++i) {
45244524
callback(callback_data, get_beams_state(false)); // Sets common_prefix_length
45254525
update_beams_from_beam_views(); // Update values (p,eos) that callback may have changed.
@@ -4556,7 +4556,7 @@ struct beam_search {
45564556

45574557
// Copy (p,eos) for each beam which may have been changed by the callback.
45584558
void update_beams_from_beam_views() {
4559-
for (size_t i=0 ; i<beams.size() ; ++i) {
4559+
for (size_t i = 0 ; i < beams.size() ; ++i) {
45604560
beams[i].p = beam_views[i].p;
45614561
beams[i].eos = beam_views[i].eos;
45624562
}

0 commit comments

Comments
 (0)