diff --git a/include/aidge/backend/cpu/data/Broadcasting.hpp b/include/aidge/backend/cpu/data/Broadcasting.hpp index 1c334b05f77dc8a2f1e7363c4e4a1c50731cd456..cb969cb54806a204072763a1672ee5266fb6347e 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 1211570cc5ba2fd6eb943ffe892dffb5c2a2c465..22977aa772e3f3f4810a59ff1fc024cc21c66bd1 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) {