concision_traits/impls/
impl_forward.rs1use crate::{Forward, ForwardMut, ForwardOnce};
7
8use ndarray::linalg::Dot;
9use ndarray::{ArrayBase, Data, Dimension};
10
11impl<F, X, Y> ForwardOnce<X> for F
12where
13 F: FnOnce(X) -> Y,
14{
15 type Output = Y;
16
17 fn forward_once(self, input: X) -> Self::Output {
18 self(input)
19 }
20}
21
22impl<F, X, Y> Forward<X> for F
23where
24 F: Fn(&X) -> Y,
25{
26 type Output = Y;
27
28 fn forward(&self, input: &X) -> Self::Output {
29 self(input)
30 }
31}
32
33impl<F, X, Y> ForwardMut<X> for F
34where
35 F: FnMut(&X) -> Y,
36{
37 type Output = Y;
38
39 fn forward_mut(&mut self, input: &X) -> Self::Output {
40 self(input)
41 }
42}
43
44impl<X, Y, A, S, D> Forward<X> for ArrayBase<S, D, A>
45where
46 A: Clone,
47 D: Dimension,
48 S: Data<Elem = A>,
49 for<'a> X: Dot<ArrayBase<S, D, A>, Output = Y>,
50{
51 type Output = Y;
52
53 fn forward(&self, input: &X) -> Self::Output {
54 input.dot(self)
55 }
56}