diff --git a/hazardflow-designs/src/examples/fir_filter.rs b/hazardflow-designs/src/examples/fir_filter.rs index 4598cfc..11bd8fe 100644 --- a/hazardflow-designs/src/examples/fir_filter.rs +++ b/hazardflow-designs/src/examples/fir_filter.rs @@ -4,33 +4,33 @@ use crate::prelude::*; use crate::std::*; impl Valid

{ - /// Window combinator + /// Window combinator. + /// /// It takes a stream of input value P and return the latest N values. fn window(self) -> Valid> - where [(); N + 1]: { - self.fsm_map(P::default().repeat::(), |ip, s| { - let ep = s.append(ip.repeat::<1>()).clip_const::(0); - let s_next = ep; + where + [(); N - 1]:, + [(); 1 + (N - 1)]:, + { + self.fsm_map(P::default().repeat::<{ N - 1 }>(), |ip, s| { + let ep = ip.repeat::<1>().append(s).resize::(); + let s_next = ep.clip_const::<{ N - 1 }>(0); (ep, s_next) }) } } impl Valid> { - /// Weight combinator - fn weight(self, weight: [u32; N]) -> Valid> { - self.map(|ip| ip.zip(Array::from(weight)).map(|(ele, weight)| ele * weight)) - } - - /// Sum combinator - /// It will add up all the elements within an array. + /// Sum combinator. + /// + /// It adds up all the elements within an array. fn sum(self) -> Valid { - self.map(|ip| ip.fold_assoc(|e1, e2| e1 + e2)) + self.map(|ip| ip.fold(0, |acc, e| acc + e)) } } /// FIR filter implementation #[synthesize] pub fn fir_filter(input: Valid) -> Valid { - input.window::<3>().weight([4, 2, 3]).sum() + input.window::<3>().map(|ip| ip.zip(Array::from([4, 2, 3])).map(|(e, wt)| e * wt)).sum() }