tract_pulse/ops/
source.rs

1use crate::internal::*;
2use tract_core::ops::source::*;
3
4register_all!(TypedSource: pulsify);
5
6pub fn pulsify(
7    _op: &TypedSource,
8    _source: &TypedModel,
9    node: &TypedNode,
10    target: &mut PulsedModel,
11    _mapping: &HashMap<OutletId, OutletId>,
12    stream_symbol: &Symbol,
13    pulse: &TDim,
14) -> TractResult<Option<TVec<OutletId>>> {
15    let pulsed_fact = PulsedFact::from_tensor_fact_pulse(&node.outputs[0].fact, stream_symbol, pulse)?;
16    let id = target.add_source(node.name.clone(), pulsed_fact)?;
17    Ok(Some(tvec!(id)))
18}
19
20#[derive(Debug, Clone, Hash)]
21pub struct PulsedSource(pub PulsedFact);
22
23
24
25impl Op for PulsedSource {
26    fn name(&self) -> Cow<str> {
27        "PulsedSource".into()
28    }
29    not_a_typed_op!();
30}
31
32impl EvalOp for PulsedSource {
33    fn is_stateless(&self) -> bool {
34        false
35    }
36
37    fn state(
38        &self,
39        _session: &mut SessionState,
40        node_id: usize,
41    ) -> TractResult<Option<Box<dyn OpState>>> {
42        Ok(Some(Box::new(SourceState(node_id))))
43    }
44}
45
46impl PulsedOp for PulsedSource {
47    fn pulsed_output_facts(&self, _inputs: &[&PulsedFact]) -> TractResult<TVec<PulsedFact>> {
48        Ok(tvec!(self.0.clone()))
49    }
50
51    fn to_typed(&self) -> Box<dyn TypedOp> {
52        Box::new(TypedSource::new(self.0.datum_type.fact(self.0.shape.clone())))
53    }
54
55    as_op!();
56}