From a5382e315c365c86e53fa0323ade1fb7d52bfa37 Mon Sep 17 00:00:00 2001
From: hrouis <houssemeddine.rouis92@gmail.com>
Date: Tue, 18 Feb 2025 15:56:33 +0100
Subject: [PATCH] support only bias of size outChannels for factory func
 limitations

---
 src/operator/FC.cpp | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/src/operator/FC.cpp b/src/operator/FC.cpp
index d73c8fd8c..54f28507b 100644
--- a/src/operator/FC.cpp
+++ b/src/operator/FC.cpp
@@ -45,8 +45,12 @@ bool Aidge::FC_Op::forwardDims(bool /*allowDataDependency*/) {
         // first check weight since it defines inChannels and outChannels
         AIDGE_ASSERT((getInput(1)->nbDims() == 2),
                     "Wrong weight Tensor dimension: {} for FC operator (should have 2 dimensions).", getInput(1)->nbDims());
-        const DimSize_t outChannels = mAttributes->template getAttr<FCAttr::TransB>() ? getInput(1)->template dims<2>()[1]:getInput(1)->template dims<2>()[0];
-        const DimSize_t inChannels = mAttributes->template getAttr<FCAttr::TransB>() ? getInput(1)->template dims<2>()[0]:getInput(1)->template dims<2>()[1];
+        const DimSize_t outChannels = mAttributes->template getAttr<FCAttr::TransB>() ?
+                                      getInput(1)->template dims<2>()[1]:
+                                      getInput(1)->template dims<2>()[0];
+        const DimSize_t inChannels = mAttributes->template getAttr<FCAttr::TransB>() ?
+                                     getInput(1)->template dims<2>()[0]:
+                                     getInput(1)->template dims<2>()[1];
         // check data
         const std::vector<DimSize_t>& inputDims = getInput(0)->dims();
         const DimIdx_t inChannelsIdx = mAttributes->template getAttr<FCAttr::TransA>() ? 1 : 0;
@@ -64,18 +68,11 @@ bool Aidge::FC_Op::forwardDims(bool /*allowDataDependency*/) {
                     nbInputFeatures, inChannels);
         }
         // check optional bias
-        const DimSize_t batchSize = static_cast<DimSize_t>(getInput(0)->size() / inChannels);
-        if(getInput(2))
-            AIDGE_ASSERT((((getInput(2)->nbDims() == 1) &&
-                    (getInput(2)->template dims<1>()[0] == outChannels)) ||
-                    ((getInput(2)->nbDims() == 2)&&
-                     (getInput(0)->nbDims() == 2)&&
-                     (getInput(2)->template dims<2>()[0] == batchSize) &&
-                     (getInput(2)->template dims<2>()[1] == outChannels)
-                     )),
-                    "Wrong bias size for FC operator.");
+        if(getInput(2)) {
+            AIDGE_ASSERT(getInput(2)->size() == outChannels, "Wrong bias size for FC operator.");
+        }
         // <batch, OutChannels>
-        mOutputs[0]->resize({batchSize, outChannels});
+        mOutputs[0]->resize({static_cast<DimSize_t>(getInput(0)->size() / inChannels), outChannels});
         return true;
     }
 
-- 
GitLab