Skip to content
Snippets Groups Projects
Commit c60708b2 authored by Michal Szczepanski's avatar Michal Szczepanski
Browse files

asserts added for null imputs

parent b776dd1a
No related branches found
No related tags found
2 merge requests!152Update Aidge export to take a graph view has an argument instead of a...,!125Operator resize
...@@ -24,6 +24,6 @@ void init_Resize(py::module& m) { ...@@ -24,6 +24,6 @@ void init_Resize(py::module& m) {
declare_registrable<Resize_Op>(m, "ResizeOp"); declare_registrable<Resize_Op>(m, "ResizeOp");
m.def("Resize", &Resize, py::arg("nb_input_dims"), py::arg("no_roi"), py::arg("no_scales"), py::arg("no_sizes"), py::arg("name") = ""); m.def("Resize", &Resize, py::arg("name") = "");
} }
} // namespace Aidge } // namespace Aidge
...@@ -53,26 +53,23 @@ bool Aidge::Resize_Op::forwardDims(bool allowDataDependency) { ...@@ -53,26 +53,23 @@ bool Aidge::Resize_Op::forwardDims(bool allowDataDependency) {
return false; return false;
} }
if (getInput(1) && !getInput(1)->empty()) { bool input1ROIPresent = getInput(1) && !getInput(1)->empty();
AIDGE_THROW_OR_ABORT(std::runtime_error, "ROI input is not supported"); bool input2ScalesPresent = getInput(2) && !getInput(2)->empty();
return false; bool input3SizesPresent = getInput(3) && !getInput(3)->empty();
}
if (getInput(2) && !getInput(2)->empty()) { if (input1ROIPresent) {
/* AIDGE_THROW_OR_ABORT(std::runtime_error, "Input #1 (ROI) is given and it is not supported.");
fmt::print("Condition scales: Input#0 and Input#2 must be provided and must have the same dimension,\
while Inputs#1 and #3 must not be provided.\n"); } else if (input2ScalesPresent) {
*/
if (!allowDataDependency) { if (!allowDataDependency) {
Log::warn("Resize_Op: unable to forwardDims() because output dims are data dependent\ Log::warn("Resize_Op: cannot execute forwardDims() as the output dimensions depend on the input #2");
on input#0 and input#2");
return false; return false;
} }
AIDGE_ASSERT(getInput(0)->nbDims() == getInput(2)->size(),\ AIDGE_ASSERT(getInput(0)->nbDims() == getInput(2)->size(),\
"input tensor and Scales must have the same dimensions."); "input #0 and input #2 (Scales) must have the same dimensions.");
std::vector<DimSize_t> outDims = getInput(0)->dims(); std::vector<DimSize_t> outDims = getInput(0)->dims();
const std::vector<DimSize_t> inDims = getInput(0)->dims(); const std::vector<DimSize_t> inDims = getInput(0)->dims();
...@@ -83,26 +80,20 @@ bool Aidge::Resize_Op::forwardDims(bool allowDataDependency) { ...@@ -83,26 +80,20 @@ bool Aidge::Resize_Op::forwardDims(bool allowDataDependency) {
for (std::size_t dim=0; dim < getInput(2)->size(); ++dim) { for (std::size_t dim=0; dim < getInput(2)->size(); ++dim) {
outDims[dim] = inDims[dim]*static_cast<int64_t*>(scales.getImpl()->hostPtr())[dim]; outDims[dim] = inDims[dim]*static_cast<int64_t*>(scales.getImpl()->hostPtr())[dim];
} }
mOutputs[0]->resize(outDims); mOutputs[0]->resize(outDims);
return true; return true;
}
if (getInput(3) && !getInput(3)->empty()) {
/* } else if (input3SizesPresent) {
fmt::print("Condition sizes: Input#0 and Input#3 must be provided and must have the same dimension,\
while Inputs#1 and #2 must not be provided.\n");
*/
if (!allowDataDependency) { if (!allowDataDependency) {
Log::warn("Resize_Op: unable to forwardDims() because output dims are data dependent\ Log::warn("Resize_Op: cannot execute forwardDims() as the output dimensions depend on the input #3");
on input#0 and input#3)");
return false; return false;
} }
AIDGE_ASSERT(getInput(0)->nbDims() == getInput(3)->size(),\ AIDGE_ASSERT(getInput(0)->nbDims() == getInput(3)->size(),\
"input tensor and Sizes must have the same dimensions."); "input #0 and input #3 (Sizes) must have the same dimensions.");
std::vector<DimSize_t> outDims = getInput(0)->dims(); std::vector<DimSize_t> outDims = getInput(0)->dims();
...@@ -112,12 +103,15 @@ bool Aidge::Resize_Op::forwardDims(bool allowDataDependency) { ...@@ -112,12 +103,15 @@ bool Aidge::Resize_Op::forwardDims(bool allowDataDependency) {
for (std::size_t dim=0; dim < getInput(3)->size(); ++dim) { for (std::size_t dim=0; dim < getInput(3)->size(); ++dim) {
outDims[dim] = static_cast<int64_t*>(sizes.getImpl()->hostPtr())[dim]; outDims[dim] = static_cast<int64_t*>(sizes.getImpl()->hostPtr())[dim];
} }
mOutputs[0]->resize(outDims); mOutputs[0]->resize(outDims);
return true; return true;
} else {
AIDGE_THROW_OR_ABORT(std::runtime_error, "Error: Either Input #2 or Input #3 must be present.");
} }
return false; return false;
} }
void Aidge::Resize_Op::setBackend(const std::string& name, Aidge::DeviceIdx_t device) { void Aidge::Resize_Op::setBackend(const std::string& name, Aidge::DeviceIdx_t device) {
......
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