mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-05-14 20:48:00 +00:00
Use M_PI to replace 3.14 constants (#16421)
### Description Use M_PI to replace 3.14 constants ### Motivation and Context Fixes #16413
This commit is contained in:
parent
48e6186b1a
commit
e2381c42f2
6 changed files with 8 additions and 8 deletions
|
|
@ -41,7 +41,7 @@ __global__ void biasSplitGeluKernel(T const* input, T const* bias, T* output) {
|
|||
auto value_right = (float)(input[index_input + HHS] + bias[index_bias + HHS]);
|
||||
|
||||
// Gelu is applied to right side only: Gelu(x) = x * 0.5 * (erf(x / sqrt(2)) + 1.0)
|
||||
float gelu_right = value_right * 0.5f * (erff(value_right / 1.41421356237f) + 1.0f);
|
||||
float gelu_right = value_right * 0.5f * (erff(value_right / static_cast<float>(M_SQRT2)) + 1.0f);
|
||||
float result = value_left * gelu_right;
|
||||
output[index_output] = static_cast<T>(result);
|
||||
index_input += TPB;
|
||||
|
|
|
|||
|
|
@ -178,7 +178,7 @@ static inline float ErfInv(float x) {
|
|||
float sgn = x < 0 ? -1.0f : 1.0f;
|
||||
x = (1 - x) * (1 + x);
|
||||
float log = std::log(x);
|
||||
float v = 2 / (3.14159f * 0.147f) + 0.5f * log;
|
||||
float v = 2 / (static_cast<float>(M_PI) * 0.147f) + 0.5f * log;
|
||||
float v2 = 1 / (0.147f) * log;
|
||||
float v3 = -v + std::sqrt(v * v - v2);
|
||||
x = sgn * std::sqrt(v3);
|
||||
|
|
@ -244,7 +244,7 @@ static inline void multiclass_probability(int64_t classcount,
|
|||
}
|
||||
}
|
||||
|
||||
static constexpr float ml_sqrt2 = 1.41421356f;
|
||||
static constexpr float ml_sqrt2 = static_cast<float>(M_SQRT2);
|
||||
|
||||
static inline float ComputeLogistic(float val) {
|
||||
float v = 1 / (1 + std::exp(-std::abs(val)));
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ static inline T bit_reverse(T num, unsigned significant_bits) {
|
|||
template <typename T>
|
||||
static T compute_angular_velocity(size_t number_of_samples, bool inverse) {
|
||||
// Calculate fundamental angular velocity
|
||||
static constexpr T pi = static_cast<T>(3.14159265);
|
||||
static constexpr T pi = static_cast<T>(M_PI);
|
||||
static constexpr T tau = 2 * pi;
|
||||
T inverse_switch = inverse ? 1.f : -1.f;
|
||||
T angular_velocity = inverse_switch * tau / number_of_samples;
|
||||
|
|
@ -196,7 +196,7 @@ static Status dft_bluestein_z_chirp(
|
|||
OpKernelContext* ctx, const Tensor* X, Tensor* Y, Tensor& b_fft, Tensor& chirp, size_t X_offset, size_t X_stride, size_t Y_offset, size_t Y_stride,
|
||||
int64_t axis, size_t dft_length, const Tensor* window, bool inverse, InlinedVector<std::complex<T>>& V,
|
||||
InlinedVector<std::complex<T>>& temp_output) {
|
||||
static constexpr T pi = static_cast<T>(3.14159265);
|
||||
static constexpr T pi = static_cast<T>(M_PI);
|
||||
|
||||
AllocatorPtr alloc;
|
||||
ORT_RETURN_IF_ERROR(ctx->GetTempSpaceAllocator(&alloc));
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ struct CosineSumWindow {
|
|||
auto* Y_data = reinterpret_cast<T*>(Y->MutableDataRaw());
|
||||
|
||||
// Calculate the radians to increment per sample
|
||||
constexpr double pi = 3.14159265;
|
||||
constexpr double pi = M_PI;
|
||||
constexpr double tau = 2 * pi;
|
||||
const size_t denominator = is_periodic ? size : size - 1;
|
||||
const double angular_increment = tau / denominator;
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ std::vector<float> ComputeGelu(const std::vector<float>& input_data) {
|
|||
|
||||
for (size_t i = 0; i < input_data.size(); i++) {
|
||||
float x = input_data[i];
|
||||
float y = x * (0.5f * (1.0f + std::erff(x / 1.41421356237f)));
|
||||
float y = x * (0.5f * (1.0f + std::erff(x / static_cast<float>(M_SQRT2))));
|
||||
output.push_back(y);
|
||||
}
|
||||
return output;
|
||||
|
|
|
|||
|
|
@ -722,7 +722,7 @@ static void DiscreteFourierTransform(
|
|||
template <typename T>
|
||||
static auto MakePureFrequency(float frequency_in_hertz, size_t signal_size, size_t sample_rate) {
|
||||
float amplitude = 4;
|
||||
float angular_velocity = frequency_in_hertz * 2 * 3.1415f;
|
||||
float angular_velocity = frequency_in_hertz * 2 * static_cast<float>(M_PI);
|
||||
std::vector<T> signal(signal_size);
|
||||
for (size_t i = 0; i < signal_size; i++) {
|
||||
T time = i / static_cast<T>(sample_rate);
|
||||
|
|
|
|||
Loading…
Reference in a new issue