Skip to content

Commit

Permalink
clip : add c++20 macro guard to lerp function in
Browse files Browse the repository at this point in the history
This commit adds a macro guard to the lerp (linear interpolation)
function in clip.cpp to avoid a conflict with the lerp function in the
<cmath> standard C++ library when using c++20.

The motivation for this change is to enable projects that use c++20 to
be able to compile clip.cpp without having to resort to patching it. The
lerp function was added to cmath in version C++20 (202002L) and is why
this is not causing any issue at the moment as C++11/C++17 is currently
used by llama.cpp.

I realize that llama.cpp uses either C++11 (or C++17 in the case for
SYCL) but wanted to ask if this would be an acceptable change just the
same.

Refs: https://en.cppreference.com/w/cpp/numeric/lerp
Signed-off-by: Daniel Bevenius <[email protected]>
  • Loading branch information
danbev committed Apr 25, 2024
1 parent 784e11d commit 6e0cc8e
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions examples/llava/clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1325,9 +1325,11 @@ bool clip_image_load_from_bytes(const unsigned char * bytes, size_t bytes_length
}

// Linear interpolation between two points
#if __cplusplus < 202002L // Check if C++ standard version is less than C++20
inline float lerp(float s, float e, float t) {
return s + (e - s) * t;
}
#endif
// Bilinear resize function
static void bilinear_resize(const clip_image_u8& src, clip_image_u8& dst, int target_width, int target_height) {
dst.nx = target_width;
Expand Down

0 comments on commit 6e0cc8e

Please sign in to comment.