22 virtual int NumBits()
const = 0;
38 double highest = (1 <<
NumBits()) - 1;
40 min = std::min(0.0, min);
41 max = std::max(0.0, max);
44 if (min == 0.0 && max == 0.0)
50 double scale = (max-min) / highest;
51 double offset = -min / scale;
54 offset = std::max(0.0, std::min(highest, offset));
56 return std::make_pair(static_cast<float>(scale), static_cast<int>(std::round(offset)));
59 int NumBits()
const override {
return 8; }
73 double highest = (1 <<
NumBits()) - 1;
75 min = std::min(0.0, min);
76 max = std::max(0.0, max);
79 if (min == 0.0 && max == 0.0)
85 double scale = (max-min) / highest ;
86 double offset = - min / scale;
89 offset = std::max(0.0, std::min(highest, offset));
92 return std::make_pair(static_cast<float>(scale), static_cast<int>(std::round(offset)-128));
95 int NumBits()
const override {
return 8; }
110 if (min == 0.0 && max == 0.0)
115 double highest = (1 << (
NumBits()-1)) - 1;
117 double extent = std::max(std::abs(min), std::abs(max));
118 double scale = extent / highest;
120 return std::make_pair(static_cast<float>(scale), 0);
138 if (min == 0.0 && max == 0.0)
143 double highest = (1 << (
NumBits()-1)) - 1;
145 double extent = std::max(std::abs(min), std::abs(max));
146 double scale = extent / highest;
148 return std::make_pair(static_cast<float>(scale), 0);
virtual OffsetScalePair ComputeScheme(double min, double max) const =0
DataType GetDataType() const override
DataType GetDataType() const override
virtual ~IQuantizationScheme()
virtual DataType GetDataType() const =0
virtual int NumBits() const =0
OffsetScalePair ComputeScheme(double min, double max) const override
int NumBits() const override
OffsetScalePair ComputeScheme(double min, double max) const override
int NumBits() const override
DataType GetDataType() const override
int NumBits() const override
OffsetScalePair ComputeScheme(double min, double max) const override
std::pair< float, int > OffsetScalePair
OffsetScalePair ComputeScheme(double min, double max) const override
int NumBits() const override
DataType GetDataType() const override