mirror of
				https://github.com/ggml-org/llama.cpp.git
				synced 2025-11-03 09:22:01 +00:00 
			
		
		
		
	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 <daniel.bevenius@gmail.com>
This commit is contained in:
		@@ -1325,7 +1325,7 @@ bool clip_image_load_from_bytes(const unsigned char * bytes, size_t bytes_length
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Linear interpolation between two points
 | 
			
		||||
inline float lerp(float s, float e, float t) {
 | 
			
		||||
inline float clip_lerp(float s, float e, float t) {
 | 
			
		||||
    return s + (e - s) * t;
 | 
			
		||||
}
 | 
			
		||||
// Bilinear resize function
 | 
			
		||||
@@ -1347,17 +1347,17 @@ static void bilinear_resize(const clip_image_u8& src, clip_image_u8& dst, int ta
 | 
			
		||||
            float y_lerp = py - y_floor;
 | 
			
		||||
 | 
			
		||||
            for (int c = 0; c < 3; c++) {
 | 
			
		||||
                float top = lerp(
 | 
			
		||||
                float top = clip_lerp(
 | 
			
		||||
                    static_cast<float>(src.buf[3 * (y_floor * src.nx + x_floor) + c]),
 | 
			
		||||
                    static_cast<float>(src.buf[3 * (y_floor * src.nx + (x_floor + 1)) + c]),
 | 
			
		||||
                    x_lerp
 | 
			
		||||
                );
 | 
			
		||||
                float bottom = lerp(
 | 
			
		||||
                float bottom = clip_lerp(
 | 
			
		||||
                    static_cast<float>(src.buf[3 * ((y_floor + 1) * src.nx + x_floor) + c]),
 | 
			
		||||
                    static_cast<float>(src.buf[3 * ((y_floor + 1) * src.nx + (x_floor + 1)) + c]),
 | 
			
		||||
                    x_lerp
 | 
			
		||||
                );
 | 
			
		||||
                dst.buf[3 * (y * target_width + x) + c] = static_cast<uint8_t>(lerp(top, bottom, y_lerp));
 | 
			
		||||
                dst.buf[3 * (y * target_width + x) + c] = static_cast<uint8_t>(clip_lerp(top, bottom, y_lerp));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user