Skip to content
Snippets Groups Projects
Commit 10eba2d3 authored by Maxence Naud's avatar Maxence Naud
Browse files

[Upd] Reshape.cpp and Gather.cpp computeOutputDims() function to check input emptyness

parent 66acc5cb
No related branches found
No related tags found
No related merge requests found
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
* *
********************************************************************************/ ********************************************************************************/
#include <cassert>
#include <cstddef> #include <cstddef>
#include <cstdint>
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -26,18 +26,22 @@ void Aidge::Gather_Op::computeOutputDims() { ...@@ -26,18 +26,22 @@ void Aidge::Gather_Op::computeOutputDims() {
AIDGE_THROW_OR_ABORT(std::runtime_error, "Input was not connected"); AIDGE_THROW_OR_ABORT(std::runtime_error, "Input was not connected");
} }
std::vector<DimSize_t> outDims = getInput(0)->dims(); if (!getInput(0)->empty()) {
const std::vector<DimSize_t> gatheredShape = this->template getAttr<GatherAttr::GatheredShape>(); std::vector<DimSize_t> outDims = getInput(0)->dims();
// TODO: check indices and gatheredShape const std::vector<DimSize_t> gatheredShape = this->template getAttr<GatherAttr::GatheredShape>();
// TODO: check indices and gatheredShape
const std::int64_t axisIdx = this->template getAttr<GatherAttr::Axis>() >= 0 ? const std::int64_t axisIdx = this->template getAttr<GatherAttr::Axis>() >= 0 ?
this->template getAttr<GatherAttr::Axis>() : this->template getAttr<GatherAttr::Axis>() :
this->template getAttr<GatherAttr::Axis>() + outDims.size(); this->template getAttr<GatherAttr::Axis>() + outDims.size();
outDims.erase(outDims.begin() + static_cast<std::size_t>(axisIdx)); outDims.erase(outDims.begin() + static_cast<std::size_t>(axisIdx));
if (!gatheredShape.empty()) if (!gatheredShape.empty())
{ {
outDims.insert(outDims.begin() + static_cast<std::size_t>(axisIdx), gatheredShape.begin(),gatheredShape.end()); outDims.insert(outDims.cbegin() + static_cast<std::size_t>(axisIdx),
} gatheredShape.cbegin(),
gatheredShape.cend());
}
mOutputs[0]->resize(outDims); mOutputs[0]->resize(outDims);
}
} }
\ No newline at end of file
...@@ -27,30 +27,32 @@ void Aidge::Reshape_Op::computeOutputDims() { ...@@ -27,30 +27,32 @@ void Aidge::Reshape_Op::computeOutputDims() {
AIDGE_THROW_OR_ABORT(std::runtime_error, "Input was not connected"); AIDGE_THROW_OR_ABORT(std::runtime_error, "Input was not connected");
} }
std::vector<DimSize_t> outDims; if (!getInput(0)->empty()) {
// variables to handle a negative dimension std::vector<DimSize_t> outDims;
bool foundNegativeDimension = false; // variables to handle a negative dimension
std::size_t outSize = 1; bool foundNegativeDimension = false;
DimIdx_t negativeIndex = 0; std::size_t outSize = 1;
DimIdx_t negativeIndex = 0;
for(std::size_t i = 0; i < this->template getAttr<ReshapeAttr::Shape>().size(); ++i)
{ for(std::size_t i = 0; i < this->template getAttr<ReshapeAttr::Shape>().size(); ++i)
std::int64_t dimSize = this->template getAttr<ReshapeAttr::Shape>()[i]; {
if (dimSize < 0) { std::int64_t dimSize = this->template getAttr<ReshapeAttr::Shape>()[i];
if (foundNegativeDimension) { if (dimSize < 0) {
AIDGE_THROW_OR_ABORT(std::runtime_error, "Found more than one negative dimension in Reshape Operator."); if (foundNegativeDimension) {
AIDGE_THROW_OR_ABORT(std::runtime_error, "Found more than one negative dimension in Reshape Operator.");
}
foundNegativeDimension = true;
dimSize = 1;
negativeIndex = static_cast<DimIdx_t>(i);
} }
foundNegativeDimension = true; outDims.push_back(static_cast<DimSize_t>(dimSize));
dimSize = 1; outSize *= static_cast<DimSize_t>(dimSize);
negativeIndex = static_cast<DimIdx_t>(i);
} }
outDims.push_back(static_cast<DimSize_t>(dimSize));
outSize *= static_cast<DimSize_t>(dimSize);
}
if (foundNegativeDimension) { if (foundNegativeDimension) {
outDims[negativeIndex] = (getInput(0) -> size()) / outSize; outDims[negativeIndex] = (getInput(0) -> size()) / outSize;
} }
mOutputs[0]->resize(outDims); mOutputs[0]->resize(outDims);
}
} }
\ No newline at end of file
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