1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use crate::{backend::Backend, Int, Tensor};

/// The quantization parameters.
#[derive(Clone, Debug)]
pub struct QuantizationParameters<B: Backend> {
    /// The scaling factor.
    pub scale: Tensor<B, 1>,
    /// The zero-point offset.
    pub offset: Option<Tensor<B, 1, Int>>,
}

/// The quantization parameters primitive.
///
/// # Remarks
///
/// This is a low-level struct used internally by the library to provide the quantization parameters
/// to the backends. It is not designed for direct usage by users, and not recommended to import
/// or use this struct directly.
///
/// Users should prefer the [QuantizationParameters] struct, which is designed for public use.
pub struct QuantizationParametersPrimitive<B: Backend> {
    /// The scaling factor.
    pub scale: B::FloatTensorPrimitive<1>,
    /// The zero-point offset.
    pub offset: Option<B::IntTensorPrimitive<1>>,
}

impl<B: Backend> From<QuantizationParameters<B>> for QuantizationParametersPrimitive<B> {
    fn from(value: QuantizationParameters<B>) -> Self {
        QuantizationParametersPrimitive {
            scale: value.scale.primitive.tensor(),
            offset: value.offset.map(|x| x.primitive),
        }
    }
}