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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#![allow(clippy::len_zero)]

use tract_nnef::internal::*;

pub mod is_inf;
pub mod is_nan;
pub mod lrn;
pub mod ml;
pub mod non_max_suppression;
pub mod multinomial;
pub mod random;

pub trait WithOnnx {
    fn with_onnx(self) -> Self;
    fn enable_onnx(&mut self);
}

impl WithOnnx for tract_nnef::framework::Nnef {
    fn enable_onnx(&mut self) {
        self.enable_tract_core();
        self.registries.push(onnx_opl_registry());
    }
    fn with_onnx(mut self) -> Self {
        self.enable_onnx();
        self
    }
}

fn onnx_opl_registry() -> Registry {
    let mut registry: Registry = Registry::new("tract_onnx");
    ml::register(&mut registry);
    non_max_suppression::register(&mut registry);
    multinomial::register(&mut registry);
    random::register(&mut registry);
    registry.register_element_wise(
        "tract_onnx_isinf",
        TypeId::of::<is_inf::IsInf>(),
        is_inf::dump,
        is_inf::parameters(),
        is_inf::load,
    );
    registry.register_unit_element_wise("tract_onnx_is_nan", &is_nan::IsNan {});
    registry.register_dumper(TypeId::of::<lrn::Lrn>(), lrn::dump);
    registry.register_primitive(
            "tract_onnx_lrn", 
            &lrn::parameters(), 
            &[("output", TypeName::Scalar.tensor())],
            lrn::load
    );
    registry
}