pub(crate) fn wire_offset_u8_as_i8(
    model: &mut TypedModel,
    model_name: &str,
    matrix: OutletId,
    matrix_name: &str,
    zero_point: &mut OutletId,
    zero_point_name: &str,
) -> TractResult<OutletId> {
    if let DatumType::U8 = model.outlet_fact(matrix)?.datum_type.unquantized() {
        match model.outlet_fact(*zero_point)?.datum_type.unquantized() {
            DatumType::U8 => {
                *zero_point = model.wire_node(
                    format!("{}.offset_{}_as_i8", model_name, zero_point_name),
                    ops::quant::offset_u8_as_i8(),
                    &[*zero_point],
                )?[0];
            }
            DatumType::I32 => {
                *zero_point = model.wire_node(
                    format!("{}.offset_{}_as_i8", model_name, zero_point_name),
                    ops::math::add::unary(rctensor0(-128i32)),
                    &[*zero_point],
                )?[0];
            }
            _ => (),
        }
        let ret = Ok(model.wire_node(
            format!("{}.offset_{}_as_i8", model_name, matrix_name),
            ops::quant::offset_u8_as_i8(),
            &[matrix],
        )?[0]);
        ret
    } else {
        Ok(matrix)
    }
}
/// Wires the offsetting of a matrix and zero point node.
///
/// Only wires nodes of u8 type and leaves nodes of different type untouched.
Wires the offsetting of a matrix and zero point node.
Only wires nodes of u8 type and leaves nodes of different type untouched.
Wires the offsetting of a matrix and zero point node . Only wires nodes of u8 type and leaves nodes of different type untouched .
pub(crate) fn wire_offset_u8_as_i8(
    model: &mut TypedModel,
    model_name: &str,
    matrix: OutletId,
    matrix_name: &str,
    zero_point: &mut OutletId,
    zero_point_name: &str,
) -> TractResult<OutletId> {
    if let DatumType::U8 = model.outlet_fact(matrix)?.datum_type.unquantized() {
        match model.outlet_fact(*zero_point)?.datum_type.unquantized() {
            DatumType::U8 => {
                *zero_point = model.wire_node(
                    format!("{}.offset_{}_as_i8", model_name, zero_point_name),
                    ops::quant::offset_u8_as_i8(),
                    &[*zero_point],
                )?[0];
            }
            DatumType::I32 => {
                *zero_point = model.wire_node(
                    format!("{}.offset_{}_as_i8", model_name, zero_point_name),
                    ops::math::add::unary(rctensor0(-128i32)),
                    &[*zero_point],
                )?[0];
            }
            _ => (),
        }
        let ret = Ok(model.wire_node(
            format!("{}.offset_{}_as_i8", model_name, matrix_name),
            ops::quant::offset_u8_as_i8(),
            &[matrix],
        )?[0]);
        ret
    } else {
        Ok(matrix)
    }
}
pub ( crate ) fn wire_offset_u8_as_i8 ( model : & mut TypedModel , model_name : & str , matrix : OutletId , matrix_name : & str , zero_point : & mut OutletId , zero_point_name : & str , ) -> TractResult < OutletId > { if let DatumType :: U8 = model . outlet_fact ( matrix ) ? . datum_type . unquantized ( ) { match model . outlet_fact ( * zero_point ) ? . datum_type . unquantized ( ) { DatumType :: U8 => { * zero_point = model . wire_node ( format ! ( " " model_name zero_point_name ) , ops :: quant :: offset_u8_as_i8 ( ) , & [ * zero_point ] , ) ? [ 0 ] ; } DatumType :: I32 => { * zero_point = model . wire_node ( format ! ( " " model_name zero_point_name ) , ops :: math :: add :: unary ( rctensor0 ( - 128i32 ) ) , & [ * zero_point ] , ) ? [ 0 ] ; } _ => ( ) , } let ret = Ok ( model . wire_node ( format ! ( " " model_name matrix_name ) , ops :: quant :: offset_u8_as_i8 ( ) , & [ matrix ] , ) ? [ 0 ] ) ; ret } else { Ok ( matrix ) } }
Wires the offsetting of a matrix and zero point node.
Wires the offsetting of a matrix and zero point node .
model
&mut TypedModel
model_name
&str
matrix
OutletId
matrix_name
&str
zero_point
&mut OutletId
zero_point_name
&str
model
&mut TypedModel
model_name
&str
matrix
OutletId
matrix_name
&str
zero_point
&mut OutletId
zero_point_name
&str