Skip to content

Commit 4ab99d8

Browse files
authored
clip : rename lerp function to avoid conflict (#6894)
This commit renamesthe 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]>
1 parent 5477041 commit 4ab99d8

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

examples/llava/clip.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,7 +1325,7 @@ bool clip_image_load_from_bytes(const unsigned char * bytes, size_t bytes_length
13251325
}
13261326

13271327
// Linear interpolation between two points
1328-
inline float lerp(float s, float e, float t) {
1328+
inline float clip_lerp(float s, float e, float t) {
13291329
return s + (e - s) * t;
13301330
}
13311331
// Bilinear resize function
@@ -1347,17 +1347,17 @@ static void bilinear_resize(const clip_image_u8& src, clip_image_u8& dst, int ta
13471347
float y_lerp = py - y_floor;
13481348

13491349
for (int c = 0; c < 3; c++) {
1350-
float top = lerp(
1350+
float top = clip_lerp(
13511351
static_cast<float>(src.buf[3 * (y_floor * src.nx + x_floor) + c]),
13521352
static_cast<float>(src.buf[3 * (y_floor * src.nx + (x_floor + 1)) + c]),
13531353
x_lerp
13541354
);
1355-
float bottom = lerp(
1355+
float bottom = clip_lerp(
13561356
static_cast<float>(src.buf[3 * ((y_floor + 1) * src.nx + x_floor) + c]),
13571357
static_cast<float>(src.buf[3 * ((y_floor + 1) * src.nx + (x_floor + 1)) + c]),
13581358
x_lerp
13591359
);
1360-
dst.buf[3 * (y * target_width + x) + c] = static_cast<uint8_t>(lerp(top, bottom, y_lerp));
1360+
dst.buf[3 * (y * target_width + x) + c] = static_cast<uint8_t>(clip_lerp(top, bottom, y_lerp));
13611361
}
13621362
}
13631363
}

0 commit comments

Comments
 (0)