mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 12:21:27 +01:00
Summary: Add cppcoreguidelines-avoid-magic-numbers exclusion to clang-tidy Remove existing nolint warnings using following script: ``` for file in `git ls-files | grep -v \.py`; do gsed '/^ *\/\/ NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)/d' -i $file; done ``` Pull Request resolved: https://github.com/pytorch/pytorch/pull/57841 Reviewed By: samestep Differential Revision: D28295045 Pulled By: malfet fbshipit-source-id: 7c6e8d1213c9593f169ed3df6a916498f1a97163
36 lines
986 B
C++
36 lines
986 B
C++
#include "sigmoid.h"
|
|
|
|
namespace dnnlowp {
|
|
|
|
using namespace std;
|
|
|
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)
|
|
template <typename T>
|
|
Sigmoid<T>::Sigmoid(double max_abs_err) : tanh_(max_abs_err) {
|
|
float x_sq = tanh_.GetSaturationRegionBegin();
|
|
|
|
in_qparams_.scale = 2 * x_sq / ((1 << (num_in_bits_ - 1)) - 1);
|
|
in_qparams_.zero_point = 1 << (num_in_bits_ - 1);
|
|
in_qparams_.precision = num_in_bits_;
|
|
// -2 x_sq is mapped to -127, 0 is mapped to 0, 2 x_sq is mapped to 127
|
|
|
|
out_qparams_.scale = 0.5 / ((1 << (num_out_bits_ - 1)) - 1);
|
|
out_qparams_.zero_point = 0;
|
|
out_qparams_.precision = num_out_bits_;
|
|
// 0 is mapped to 0, 1/2 is mapped to 127, 1 is mapped to 254
|
|
}
|
|
|
|
template <typename T>
|
|
T Sigmoid<T>::Compute(T x) const {
|
|
T temp = tanh_.Compute(x);
|
|
assert(temp >= 1);
|
|
assert(temp < (1 << num_out_bits_));
|
|
return temp - 1;
|
|
}
|
|
|
|
template class Sigmoid<uint8_t>;
|
|
template class Sigmoid<uint16_t>;
|
|
template class Sigmoid<int32_t>;
|
|
|
|
} // namespace dnnlowp
|