incin_core/nn/
max_pool2d.rs1use crate::backend_authoring::Execute;
2use crate::err::{Error, Result};
3use crate::exec::Capabilities;
4use crate::nn::{Module, TrainMode};
5use crate::shapes::{DynShape, Shape};
6use crate::tensor::base::Tensor;
7
8use typenum::Unsigned;
9
10#[derive(Debug, Clone)]
11pub struct MaxPool2d<K: Unsigned, S: Unsigned, P: Unsigned = typenum::U0, D: Unsigned = typenum::U1>
13{
14 _phantom: core::marker::PhantomData<(K, S, P, D)>,
15}
16
17impl<K: Unsigned, S: Unsigned, P: Unsigned, D: Unsigned, B: crate::tensor::backend::VariableBackend>
18 crate::nn::VisitParameters<B> for MaxPool2d<K, S, P, D>
19{
20 fn visit_parameters<V: crate::nn::ParameterVisitor<B>>(
21 &self,
22 _: &crate::nn::StatePath,
23 _: &mut V,
24 ) -> Result<()> {
25 Ok(())
26 }
27}
28
29impl<K: Unsigned, S: Unsigned, P: Unsigned, D: Unsigned> MaxPool2d<K, S, P, D> {
30 pub fn new() -> Result<Self> {
32 Ok(Self {
33 _phantom: core::marker::PhantomData,
34 })
35 }
36}
37
38impl<K: Unsigned, S: Unsigned, P: Unsigned, D: Unsigned> TrainMode for MaxPool2d<K, S, P, D> {}
42
43impl<
44 I: Shape + DynShape + crate::shapes::Pool2dShape<K, S, P, D>,
45 K: Unsigned,
46 S: Unsigned,
47 P: Unsigned,
48 D: Unsigned,
49 B: crate::tensor::backend::VariableBackend + Execute<crate::exec::catalog::op::MaxPool2d>,
50> Module<Tensor<I, B>> for MaxPool2d<K, S, P, D>
51where
52 B: Capabilities,
53 <B as Execute<crate::exec::catalog::op::MaxPool2d>>::Output: Into<B::Storage<f32>>,
54{
55 type Output = Tensor<I::Output, B>;
57 type Error = Error;
59
60 #[inline]
61 fn forward(&self, x: Tensor<I, B>) -> core::result::Result<Self::Output, Error> {
63 x.max_pool2d::<K, S, P, D>()
64 }
65}