#![allow(dead_code)]
use tinymind::int8::{QDense, QSoftmax, Requantizer, qrelu};
pub const NUM_INPUTS: usize = 4;
pub const NUM_OUTPUTS: usize = 3;
pub const INPUT_SCALE: f32 = 0.007843138;
pub const INPUT_ZERO_POINT: i8 = -1;
pub const H1_SCALE: f32 = 0.00622549;
pub const H1_ZERO_POINT: i8 = -128;
pub const FC2_SCALE: f32 = 0.023566175;
pub const FC2_ZERO_POINT: i8 = 15;
pub const PROBS_SCALE: f32 = 0.00390625;
pub const PROBS_ZERO_POINT: i8 = -128;
pub const OUTPUT_SCALE: f32 = PROBS_SCALE;
pub const OUTPUT_ZERO_POINT: i8 = PROBS_ZERO_POINT;
pub static FC1_WEIGHTS: [[i8; 4]; 10] = [
[-32, -95, 111, 48],
[79, 16, -48, -111],
[-79, 127, 64, 0],
[32, -32, -95, 111],
[-127, 79, 16, -48],
[-16, -79, 127, 64],
[95, 32, -32, -95],
[-64, -127, 79, 16],
[48, -16, -79, 127],
[-111, 95, 32, -32],
];
pub static FC1_BIASES: [i32; 10] = [4048, -4048, 8096, 0, -8096, 4048, -4048, 8096, 0, -8096];
pub static FC1: QDense<'static, 4, 10> = QDense {
weights: &FC1_WEIGHTS,
biases: Some(&FC1_BIASES),
input_zero_point: -1,
requantizer: Requantizer {
multiplier: 1363397261,
shift: 6,
zero_point: -128,
qmin: -128,
qmax: 127,
},
};
pub static FC2_WEIGHTS: [[i8; 10]; 3] = [
[-64, -127, 79, 16, -48, -111, 95, 32, -32, -95],
[48, -16, -79, 127, 64, 0, -64, -127, 79, 16],
[-111, 95, 32, -32, -95, 111, 48, -16, -79, 127],
];
pub static FC2_BIASES: [i32; 3] = [-2550, 5100, 0];
pub static FC2: QDense<'static, 10, 3> = QDense {
weights: &FC2_WEIGHTS,
biases: Some(&FC2_BIASES),
input_zero_point: -128,
requantizer: Requantizer {
multiplier: 1143537855,
shift: 7,
zero_point: 15,
qmin: -128,
qmax: 127,
},
};
pub static PROBS: QSoftmax = QSoftmax {
input_multiplier: 1619455232,
input_left_shift: 21,
diff_min: -992,
};
pub fn forward(input: &[i8; NUM_INPUTS]) -> [i8; NUM_OUTPUTS] {
let x0 = FC1.forward(input).map(|v| qrelu(v, H1_ZERO_POINT));
let x1 = FC2.forward(&x0);
PROBS.forward(&x1)
}