From f4815323169867cbe44bdcd29ca2369260eff9bc Mon Sep 17 00:00:00 2001
From: Gallasko <gallasko@gmail.com>
Date: Thu, 3 Apr 2025 16:47:14 +0200
Subject: [PATCH] feat: Added AvgPooling2D export op

---
 aidge_export_cpp/kernels/pooling.hpp |  2 +-
 aidge_export_cpp/operators.py        | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/aidge_export_cpp/kernels/pooling.hpp b/aidge_export_cpp/kernels/pooling.hpp
index 667e1a9..a86fd41 100644
--- a/aidge_export_cpp/kernels/pooling.hpp
+++ b/aidge_export_cpp/kernels/pooling.hpp
@@ -86,7 +86,7 @@ void pooling_forward(
                     outputs[oOffset + output] = maxVal;
                 }
                 else if (POOLING_TYPE == Average) {
-                    int32_t sum = 0;
+                    Output_T sum = 0;
 
                     for (int sy = 0; sy < POOL_HEIGHT; ++sy) {
                         if ((PADDING_Y != 0
diff --git a/aidge_export_cpp/operators.py b/aidge_export_cpp/operators.py
index c89236b..5abb137 100644
--- a/aidge_export_cpp/operators.py
+++ b/aidge_export_cpp/operators.py
@@ -248,6 +248,20 @@ class MaxPoolCPP(ExportNodeCpp):
 
         _setup_pooling(self)
 
+@ExportLibCpp.register("AvgPooling2D", aidge_core.ImplSpec(aidge_core.IOSpec(aidge_core.dtype.float32)))
+class AvgPoolCPP(ExportNodeCpp):
+    def __init__(self, node, mem_info):
+        super().__init__(node, mem_info)
+
+        # No padding with MaxPooling
+        # Use PaddedMaxPooling to add padding attribute
+        self.attributes["padding"] = [0, 0]
+        self.attributes["pool_type"] = "Average"
+        self.attributes["activation"] = "Linear"
+        self.attributes["rescaling"] = "NoScaling"
+
+        _setup_pooling(self)
+
 @ExportLibCpp.register_metaop("PaddedMaxPooling2D", aidge_core.ImplSpec(aidge_core.IOSpec(aidge_core.dtype.float32)))
 class PaddedMaxPoolCPP(ExportNodeCpp):
     def __init__(self, node, mem_info):
-- 
GitLab