Skip to content
Snippets Groups Projects
Commit 83c6f795 authored by Houssem ROUIS's avatar Houssem ROUIS Committed by Maxence Naud
Browse files

minor cleanups

parent be5d146b
No related branches found
No related tags found
2 merge requests!50version 0.2.0,!30add broadcasting for Arithmetic operators
......@@ -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
......
......@@ -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) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment