use crate::{shapes::*, tensor::*, tensor_ops::*};
use super::{Module, NonMutableModule, ZeroSizedModule};
#[derive(Clone, Copy, Default)]
pub struct AvgPoolGlobal;
#[derive(Clone, Copy, Default)]
pub struct MaxPoolGlobal;
#[derive(Clone, Copy, Default)]
pub struct MinPoolGlobal;
macro_rules! impl_pools {
($PoolTy:ty, $Method:ident) => {
impl ZeroSizedModule for $PoolTy {}
impl NonMutableModule for $PoolTy {}
impl<C: Dim, H: Dim, W: Dim, E: Dtype, D: Device<E>, T: Tape<E, D>>
Module<Tensor<(C, H, W), E, D, T>> for $PoolTy
{
type Output = Tensor<(C,), E, D, T>;
type Error = D::Err;
fn try_forward(
&self,
input: Tensor<(C, H, W), E, D, T>,
) -> Result<Self::Output, D::Err> {
input.$Method()
}
}
impl<B: Dim, C: Dim, H: Dim, W: Dim, E: Dtype, D: Device<E>, T: Tape<E, D>>
Module<Tensor<(B, C, H, W), E, D, T>> for $PoolTy
{
type Output = Tensor<(B, C), E, D, T>;
type Error = D::Err;
fn try_forward(
&self,
input: Tensor<(B, C, H, W), E, D, T>,
) -> Result<Self::Output, D::Err> {
input.$Method()
}
}
};
}
impl_pools!(AvgPoolGlobal, try_mean);
impl_pools!(MaxPoolGlobal, try_max);
impl_pools!(MinPoolGlobal, try_min);