scirs2_neural/layers/conv/
mod.rs

1//! Convolutional neural network layers implementation
2//!
3//! This module provides implementations of convolution layers for neural networks,
4//! including Conv2D, Conv3D, and their transpose versions, as well as comprehensive
5//! pooling layers for 1D, 2D, and 3D data.
6//! # Module Organization
7//! - [`common`] - Common types, enums, and utility functions
8//! - [`conv2d`] - 2D convolution implementation with im2col operations
9//! - [`pooling`] - All pooling layer implementations (standard and adaptive)
10
11pub mod common;
12pub mod conv2d;
13pub mod pooling;
14
15// Re-export main types and functions for backward compatibility
16pub use common::PaddingMode;
17pub use conv2d::Conv2D;
18pub use pooling::{
19    MaxPool2D,
20    // AdaptiveAvgPool1D, AdaptiveAvgPool2D, AdaptiveAvgPool3D, AdaptiveMaxPool1D, AdaptiveMaxPool2D,
21    // AdaptiveMaxPool3D, GlobalAvgPool2D,
22};
23
24#[cfg(test)]
25mod tests {
26    use super::*;
27    use crate::layers::Layer;
28
29    #[test]
30    fn test_conv2d_basic() {
31        let conv = Conv2D::<f64>::new(3, 8, (3, 3), (1, 1), None).unwrap();
32        assert_eq!(conv.layer_type(), "Conv2D");
33        assert!(conv.parameter_count() > 0);
34    }
35
36    #[test]
37    fn test_maxpool2d_basic() {
38        let pool = MaxPool2D::<f64>::new((2, 2), (2, 2), None).unwrap();
39        assert_eq!(pool.layer_type(), "MaxPool2D");
40        assert_eq!(pool.parameter_count(), 0);
41    }
42
43    /*
44    #[test]
45    fn test_adaptive_pools() {
46        let adaptive_avg = AdaptiveAvgPool2D::<f64>::new((7, 7), None).unwrap();
47        assert_eq!(adaptive_avg.layer_type(), "AdaptiveAvgPool2D");
48
49        let adaptive_max = AdaptiveMaxPool2D::<f64>::new((7, 7), None).unwrap();
50        assert_eq!(adaptive_max.layer_type(), "AdaptiveMaxPool2D");
51
52        let global_pool = GlobalAvgPool2D::<f64>::new(None).unwrap();
53        assert_eq!(global_pool.layer_type(), "GlobalAvgPool2D");
54    }
55    */
56}