use crate::backend_authoring::Execute;
use crate::err::{Error, Result};
use crate::exec::Capabilities;
use crate::nn::{Module, TrainMode};
use crate::shapes::{DynShape, Shape};
use crate::tensor::base::Tensor;
use typenum::Unsigned;
#[derive(Debug, Clone)]
pub struct MaxPool2d<K: Unsigned, S: Unsigned, P: Unsigned = typenum::U0, D: Unsigned = typenum::U1>
{
_phantom: core::marker::PhantomData<(K, S, P, D)>,
}
impl<K: Unsigned, S: Unsigned, P: Unsigned, D: Unsigned, B: crate::tensor::backend::VariableBackend>
crate::nn::VisitParameters<B> for MaxPool2d<K, S, P, D>
{
fn visit_parameters<V: crate::nn::ParameterVisitor<B>>(
&self,
_: &crate::nn::StatePath,
_: &mut V,
) -> Result<()> {
Ok(())
}
}
impl<K: Unsigned, S: Unsigned, P: Unsigned, D: Unsigned> MaxPool2d<K, S, P, D> {
pub fn new() -> Result<Self> {
Ok(Self {
_phantom: core::marker::PhantomData,
})
}
}
impl<K: Unsigned, S: Unsigned, P: Unsigned, D: Unsigned> TrainMode for MaxPool2d<K, S, P, D> {}
impl<
I: Shape + DynShape + crate::shapes::Pool2dShape<K, S, P, D>,
K: Unsigned,
S: Unsigned,
P: Unsigned,
D: Unsigned,
B: crate::tensor::backend::VariableBackend + Execute<crate::exec::catalog::op::MaxPool2d>,
> Module<Tensor<I, B>> for MaxPool2d<K, S, P, D>
where
B: Capabilities,
<B as Execute<crate::exec::catalog::op::MaxPool2d>>::Output: Into<B::Storage<f32>>,
{
type Output = Tensor<I::Output, B>;
type Error = Error;
#[inline]
fn forward(&self, x: Tensor<I, B>) -> core::result::Result<Self::Output, Error> {
x.max_pool2d::<K, S, P, D>()
}
}