From 0d72207ac309e3e63f8e8646d082aa9479d63b39 Mon Sep 17 00:00:00 2001 From: xaedes Date: Mon, 8 May 2023 16:56:41 +0200 Subject: [PATCH] c++ in baby-llama example use c++ includes instead of c includes use std::min, std::max instead of MIN, MAX macros --- examples/baby-llama/baby-llama.cpp | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/examples/baby-llama/baby-llama.cpp b/examples/baby-llama/baby-llama.cpp index 0f260d094..7e940bbea 100644 --- a/examples/baby-llama/baby-llama.cpp +++ b/examples/baby-llama/baby-llama.cpp @@ -1,13 +1,8 @@ #include "ggml.h" #include -#include +#include #include -#include - -#undef MIN -#undef MAX -#define MIN(a, b) ((a) < (b) ? (a) : (b)) -#define MAX(a, b) ((a) > (b) ? (a) : (b)) +#include float frand() { return (float)rand()/(float)RAND_MAX; @@ -1068,7 +1063,7 @@ void get_example_targets(int example_id, struct ggml_tensor * tokens_input, stru float z = (y+1.0f)*0.5f; // scale to [0..1] z += (frand()-0.5f)*(randomness/n_vocab); z = (z < 0.0f) ? 0.0f : (z > 1.0f) ? 1.0f : z; // clamp to [0..1] - int token = MAX(1,MIN(1+(int)(z*(float)(n_vocab-1)), n_vocab-1)); + int token = std::max(1,std::min(1+(int)(z*(float)(n_vocab-1)), n_vocab-1)); ggml_set_f32_1d(targets, (i-1)*n_vocab + token, +1.0f); if (i