1 // Copyright 2018 Google Inc. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at: 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 /// Parameters that determine the mapping of quantized values to real values. Quantized values can 16 /// be mapped to float values using the following conversion: 17 /// `realValue = scale * (quantizedValue - zeroPoint)`. 18 public struct QuantizationParameters: Equatable, Hashable { 19 /// The difference between real values corresponding to consecutive quantized values differing by 20 /// 1. For example, the range of quantized values for `UInt8` data type is [0, 255]. 21 public let scale: Float 22 23 /// The quantized value that corresponds to the real 0 value. 24 public let zeroPoint: Int 25 26 /// Creates a new instance with the given values. 27 /// 28 /// - Parameters: 29 /// - scale: The scale value for asymmetric quantization. 30 /// - zeroPoint: The zero point for asymmetric quantization. 31 init(scale: Float, zeroPoint: Int) { 32 self.scale = scale 33 self.zeroPoint = zeroPoint 34 } 35 } 36