TinyLlama.cpp 1.0
A lightweight C++ implementation of the TinyLlama language model
Loading...
Searching...
No Matches
model_macros.h
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <cmath>
5
6#ifdef _MSC_VER
7#ifndef NOMINMAX
8#define NOMINMAX
9#endif
10#endif
11
12#ifdef min
13#undef min
14#endif
15
16#ifdef max
17#undef max
18#endif
19
20namespace detail {
21template <typename T>
22inline T safe_min(T a, T b) {
23 return (std::min)(a, b); // Parentheses prevent macro expansion
24}
25
26template <typename T>
27inline T safe_max(T a, T b) {
28 return (std::max)(a, b); // Parentheses prevent macro expansion
29}
30
31inline float safe_sqrt(float x) {
32 return (std::sqrt)(x); // Parentheses prevent macro expansion
33}
34} // namespace detail
35
36#define SAFE_MIN(a, b) detail::safe_min((a), (b))
37#define SAFE_MAX(a, b) detail::safe_max((a), (b))
38#define SAFE_SQRT(x) detail::safe_sqrt(x)
T safe_max(T a, T b)
T safe_min(T a, T b)
float safe_sqrt(float x)