diff --git a/src/operator/MatMul.cpp b/src/operator/MatMul.cpp index 4bb54e83b69b200215a5ae7a274e6b2692656380..4e35ba0933f3748fc0a6d9cd4c2a34de5152d4df 100644 --- a/src/operator/MatMul.cpp +++ b/src/operator/MatMul.cpp @@ -20,6 +20,9 @@ const std::string Aidge::MatMul_Op::Type = "MatMul"; void Aidge::MatMul_Op::computeOutputDims() { + if (!getInput(0) || !getInput(1)) { + AIDGE_THROW_OR_ABORT(std::runtime_error, "Missing input. Cannot compute output dimensions for MatMul Operator."); + } if (!getInput(0)->empty() && !getInput(1)->empty()) { const auto dims0 = getInput(0)->dims(); @@ -27,18 +30,14 @@ void Aidge::MatMul_Op::computeOutputDims() { if (dims0.size() > 2 && dims1.size() > 2) { - bool supportedSizes = true; std::size_t d0 = dims0.size()-3, d1 = dims1.size()-3; - while(d0>0 && d1>0 && supportedSizes) + for (std::size_t d0 = dims0.size()-3, d1 = dims1.size()-3; + (d0>0) && (d1>0); + --d0, --d1) { if(dims0[d0] != dims1[d1]) - supportedSizes = false; - - d0--; - d1--; + AIDGE_THROW_OR_ABORT(std::runtime_error, "Unsupported sizes for MatMul!"); } - if(!supportedSizes) - AIDGE_THROW_OR_ABORT(std::runtime_error, "Unsupported sizes for MatMul!"); } std::size_t secondToLastIdx2 = dims1.size()>1 ? dims1.size() - 2 : dims1.size() - 1;