#![allow(dead_code)]
use tinymind::int8::{LUT_SIZE, QDense, Requantizer, apply_lut, qrelu};
pub const NUM_INPUTS: usize = 3;
pub const NUM_OUTPUTS: usize = 2;
pub const INPUT_SCALE: f32 = 0.007843138;
pub const INPUT_ZERO_POINT: i8 = -1;
pub const H1_SCALE: f32 = 0.004509804;
pub const H1_ZERO_POINT: i8 = -128;
pub const H2_SCALE: f32 = 0.0060324753;
pub const H2_ZERO_POINT: i8 = -128;
pub const FC3_SCALE: f32 = 0.005711566;
pub const FC3_ZERO_POINT: i8 = -1;
pub const OUT_SCALE: f32 = 0.00390625;
pub const OUT_ZERO_POINT: i8 = -128;
pub const OUTPUT_SCALE: f32 = OUT_SCALE;
pub const OUTPUT_ZERO_POINT: i8 = OUT_ZERO_POINT;
pub static FC1_WEIGHTS: [[i8; 3]; 8] = [
[-48, -111, 95],
[64, 0, -64],
[-95, 111, 48],
[16, -48, -111],
[127, 64, 0],
[-32, -95, 111],
[79, 16, -48],
[-79, 127, 64],
];
pub static FC1_BIASES: [i32; 8] = [-4048, 8096, 0, -8096, 4048, -4048, 8096, 0];
pub static FC1: QDense<'static, 3, 8> = QDense {
weights: &FC1_WEIGHTS,
biases: Some(&FC1_BIASES),
input_zero_point: -1,
requantizer: Requantizer {
multiplier: 1882080981,
shift: 6,
zero_point: -128,
qmin: -128,
qmax: 127,
},
};
pub static FC2_WEIGHTS: [[i8; 8]; 4] = [
[32, -32, -95, 111, 48, -16, -79, 127],
[-127, 79, 16, -48, -111, 95, 32, -32],
[-16, -79, 127, 64, 0, -64, -127, 79],
[95, 32, -32, -95, 111, 48, -16, -79],
];
pub static FC2_BIASES: [i32; 4] = [0, -14080, 7040, -7040];
pub static FC2: QDense<'static, 8, 4> = QDense {
weights: &FC2_WEIGHTS,
biases: Some(&FC2_BIASES),
input_zero_point: -128,
requantizer: Requantizer {
multiplier: 1618073385,
shift: 7,
zero_point: -128,
qmin: -128,
qmax: 127,
},
};
pub static FC3_WEIGHTS: [[i8; 4]; 2] = [[127, 54, -18, -91], [-54, -127, 109, 36]];
pub static FC3_BIASES: [i32; 2] = [6015, -6015];
pub static FC3: QDense<'static, 4, 2> = QDense {
weights: &FC3_WEIGHTS,
biases: Some(&FC3_BIASES),
input_zero_point: -128,
requantizer: Requantizer {
multiplier: 2000251025,
shift: 7,
zero_point: -1,
qmin: -128,
qmax: 127,
},
};
pub static OUT_LUT: [i8; LUT_SIZE] = [
-44, -44, -44, -44, -43, -43, -43, -42, -42, -42, -41, -41, -41, -40, -40, -40, -39, -39, -39,
-38, -38, -38, -37, -37, -37, -36, -36, -36, -35, -35, -35, -34, -34, -34, -33, -33, -33, -32,
-32, -32, -31, -31, -30, -30, -30, -29, -29, -29, -28, -28, -28, -27, -27, -27, -26, -26, -26,
-25, -25, -25, -24, -24, -23, -23, -23, -22, -22, -22, -21, -21, -21, -20, -20, -20, -19, -19,
-19, -18, -18, -17, -17, -17, -16, -16, -16, -15, -15, -15, -14, -14, -13, -13, -13, -12, -12,
-12, -11, -11, -11, -10, -10, -9, -9, -9, -8, -8, -8, -7, -7, -7, -6, -6, -5, -5, -5, -4, -4,
-4, -3, -3, -3, -2, -2, -1, -1, -1, 0, 0, 0, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 7,
7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 15, 15, 15, 16, 16,
16, 17, 17, 17, 18, 18, 19, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 22, 23, 23, 23, 24, 24, 25,
25, 25, 26, 26, 26, 27, 27, 27, 28, 28, 28, 29, 29, 29, 30, 30, 30, 31, 31, 32, 32, 32, 33, 33,
33, 34, 34, 34, 35, 35, 35, 36, 36, 36, 37, 37, 37, 38, 38, 38, 39, 39, 39, 40, 40, 40, 41, 41,
41, 42, 42, 42, 43, 43, 43, 44, 44, 44, 44, 45,
];
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).map(|v| qrelu(v, H2_ZERO_POINT));
let x2 = FC3.forward(&x1);
x2.map(|v| apply_lut(v, &OUT_LUT))
}