From 09630717356b53423d834fd9d7007cce3edbc2c8 Mon Sep 17 00:00:00 2001
From: hrouis <houssemeddine.rouis92@gmail.com>
Date: Fri, 26 Jan 2024 14:28:47 +0100
Subject: [PATCH] minor cleanups

---
 .../aidge/backend/cpu/data/Broadcasting.hpp   | 31 +++++++++++++++----
 src/data/Broadcasting.cpp                     |  4 +--
 2 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/include/aidge/backend/cpu/data/Broadcasting.hpp b/include/aidge/backend/cpu/data/Broadcasting.hpp
index 1c334b05..cb969cb5 100644
--- a/include/aidge/backend/cpu/data/Broadcasting.hpp
+++ b/include/aidge/backend/cpu/data/Broadcasting.hpp
@@ -17,13 +17,32 @@
 namespace Aidge {
 
 // Function to broadCast an input dims vector into the same size as an outputDims vector
-std::vector<std::size_t> getBroadcastedDims(const std::vector<std::size_t>& outputDims, const std::vector<std::size_t>& dimsToBroadcast);
 
-// Function to get multi-dimensional indices from a flattened index
-std::vector<std::size_t> getMultiDimIndices(const std::vector<std::size_t>& dimensions, std::size_t idx);
-
-// Function to get a flattened index from multi-dimensional indices
-std::size_t getFlattenedIndex(const std::vector<std::size_t>& dimensions, const std::vector<std::size_t>& indices);
+    /**
+     * @brief  Broadcast an input dims vector into the same size as an outputDims vector
+     * @details The missing dimensions would be completed by 1
+     * @param outputDims The vector of dimensions to follow 
+     * @param dimsToBroadcast The vecotr of dimensions to braodcast
+     * @return std::vector<std::size_t> a broadcasted vector by addding 1 on the missing dimensions.
+     */
+    std::vector<std::size_t> getBroadcastedDims(const std::vector<std::size_t>& outputDims, const std::vector<std::size_t>& dimsToBroadcast);
+
+    /**
+     * @brief Get a vector of indexes along the dimensions vector from a flattened index
+     * @param dimensions The vector of dimensions we want the indexes on
+     * @param idx The flattened index
+     * @return std::vector<std::size_t> vector of indexes along dimensions.
+     */
+    std::vector<std::size_t> getMultiDimIndices(const std::vector<std::size_t>& dimensions, std::size_t idx);
+
+    // Function to get a flattened index from multi-dimensional indices
+    /**
+     * @brief Get a flattened index the dimensions vector from a given vector of indices on a broadcasted vector
+     * @param dimensions The vector of dimensions we want the flattened index on
+     * @param indices The vector of indices we want to flatten
+     * @return std::size_t The flattened index on the dimensions vector
+     */
+    std::size_t getFlattenedIndex(const std::vector<std::size_t>& dimensions, const std::vector<std::size_t>& indices);
 
 } // namespace Aidge
 
diff --git a/src/data/Broadcasting.cpp b/src/data/Broadcasting.cpp
index 1211570c..22977aa7 100644
--- a/src/data/Broadcasting.cpp
+++ b/src/data/Broadcasting.cpp
@@ -13,7 +13,7 @@
 
 std::vector<std::size_t> Aidge::getBroadcastedDims(const std::vector<std::size_t>& outputDims, const std::vector<std::size_t>& dimsToBroadcast){
     std::vector<std::size_t> broadcastedDims(outputDims.size(), 1);
-		for(std::size_t j=dimsToBroadcast.size()-1; j+1>0; --j)
+		for(int j=dimsToBroadcast.size()-1; j>=0; --j)
 		{
 			std::size_t idx = outputDims.size() - (dimsToBroadcast.size()-j);
 			broadcastedDims[idx] = dimsToBroadcast[j];
@@ -21,7 +21,7 @@ std::vector<std::size_t> Aidge::getBroadcastedDims(const std::vector<std::size_t
     return broadcastedDims;
 }
 
-std::vector<std::size_t> Aidge::getMultiDimIndices(const std::vector<size_t>& dimensions, std::size_t idx){
+std::vector<std::size_t> Aidge::getMultiDimIndices(const std::vector<std::size_t>& dimensions, std::size_t idx){
     std::vector<std::size_t> indices(dimensions.size(), 0);
 
     for (int i = dimensions.size() - 1; i >= 0; --i) {
-- 
GitLab