convolve-nd 0.1.0

A small library to perform convolution operations on arrays of upto 3 dimensions using arbitrarily-sized separable kernels
Documentation
use ndarray::{Dimension, Ix1, Ix2, Ix3};

pub trait DimensionIterator {
    type Item: Copy;
    
    fn into_iter(self) -> impl IntoIterator<Item = Self::Item>;
}

impl DimensionIterator for Ix1 {
    type Item = usize;

    fn into_iter(self) -> impl IntoIterator<Item=Self::Item> {
        let [x] = self.slice() else {
            panic!("Expected 2d slice")
        };
        let x = *x;

        0..x
    }
}


impl DimensionIterator for Ix2 {
    type Item = (usize, usize);

    fn into_iter(self) -> impl IntoIterator<Item=Self::Item> {
        let [y, x] = self.slice() else {
            panic!("Expected 2d slice")
        };
        
        let y = *y;
        let x = *x;

        (0..y).flat_map(move |y| (0..x).map(move |x| (y, x)))
    }
}

impl DimensionIterator for Ix3 {
    type Item = (usize, usize, usize);

    fn into_iter(self) -> impl IntoIterator<Item=Self::Item> {
        let [y, x, z] = self.slice() else {
            panic!("Expected 3d slice")
        };

        let y = *y;
        let x = *x;
        let z = *z;

        (0..y).flat_map(move |y| (0..x).flat_map(move |x| (0..z).map(move |z| (y, x, z))))
    }
}