pytorch/caffe2/quantization/server/sigmoid.cc
Nikita Shulga 3a66a1cb99 [clang-tidy] Exclude cppcoreguidelines-avoid-magic-numbers (#57841)
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
2021-05-07 20:02:33 -07:00

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