nnapi/
operand.rs

1use nnapi_sys::{ANeuralNetworksOperandType, OperandCode};
2
3#[derive(Debug, Clone)]
4pub struct Operand {
5    pub inner: ANeuralNetworksOperandType,
6    pub len: usize,
7    pub dimensions: Vec<u32>
8}
9
10impl Operand {
11    pub fn tensor(dtype: OperandCode, dimensions: Vec<u32>, scale: f32, zero_point: i32) -> Self {
12        Operand {
13            inner: ANeuralNetworksOperandType {
14                type_: dtype as i32,
15                dimensionCount: dimensions.len() as u32,
16                dimensions: dimensions.as_ptr(),
17                scale,
18                zeroPoint: zero_point,
19            },
20            len: dimensions.iter().product::<u32>() as usize,
21            dimensions
22        }
23    }
24
25    #[inline]
26    pub fn activation() -> Self {
27        Operand {
28            inner: ANeuralNetworksOperandType {
29                type_: OperandCode::ANEURALNETWORKS_INT32 as i32,
30                dimensionCount: 0,
31                dimensions: std::ptr::null_mut(),
32                scale: 0.,
33                zeroPoint: 0,
34            },
35            len: 0,
36            dimensions: vec![],
37        }
38    }
39}