From 8542093178d4217dc0ecb3ecebe7dd710e588a97 Mon Sep 17 00:00:00 2001
From: Olivier BICHLER <olivier.bichler@cea.fr>
Date: Wed, 1 May 2024 11:29:31 +0200
Subject: [PATCH] Clarified shape errors

---
 src/operator/Add.cpp | 3 ++-
 src/operator/Div.cpp | 3 ++-
 src/operator/Mul.cpp | 6 ++----
 src/operator/Pow.cpp | 3 ++-
 src/operator/Sub.cpp | 3 ++-
 5 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/operator/Add.cpp b/src/operator/Add.cpp
index 6bafb3b79..9b77ffcbe 100644
--- a/src/operator/Add.cpp
+++ b/src/operator/Add.cpp
@@ -63,7 +63,8 @@ bool Aidge::Add_Op::forwardDims(bool /*allowDataDependency*/) {
                         *it = dim;
                     }
                     else if ((dim != *it) && (dim != 1)) {
-                        AIDGE_THROW_OR_ABORT(std::runtime_error, "Unsupported Tensor shape for Add operation: {}", outDims);
+                        AIDGE_THROW_OR_ABORT(std::runtime_error, "Incompatible Tensor shape for Add Operation: {} for previous inputs vs {} for input#{}",
+                            outDims, getInput(i)->dims(), i);
                     }
                 }
             }
diff --git a/src/operator/Div.cpp b/src/operator/Div.cpp
index 813ab774b..e6300d08c 100644
--- a/src/operator/Div.cpp
+++ b/src/operator/Div.cpp
@@ -44,7 +44,8 @@ bool Aidge::Div_Op::forwardDims(bool /*allowDataDependency*/) {
                 outDims[out_id] = lowDims[low_id];
             }
             else if ((lowDims[low_id] != 1) && (lowDims[low_id] != outDims[out_id])) {
-                AIDGE_THROW_OR_ABORT(std::runtime_error, "Unsupported Tensor shape for Div Operation: {}", outDims);
+                AIDGE_THROW_OR_ABORT(std::runtime_error, "Incompatible Tensor shape for Div Operation: {} for input#0 vs {} for input#1",
+                    inputsDims0, inputsDims1);
             }
             --out_id;
             --low_id;
diff --git a/src/operator/Mul.cpp b/src/operator/Mul.cpp
index 5a25e4dd4..426de388f 100644
--- a/src/operator/Mul.cpp
+++ b/src/operator/Mul.cpp
@@ -45,7 +45,8 @@ bool Aidge::Mul_Op::forwardDims(bool /*allowDataDependency*/) {
                 outDims[out_id] = lowDims[low_id];
             }
             else if ((lowDims[low_id] != 1) && (lowDims[low_id] != outDims[out_id])) {
-                AIDGE_THROW_OR_ABORT(std::runtime_error, "Unsupported Tensor shape for Mul Operation: {}", outDims);
+                AIDGE_THROW_OR_ABORT(std::runtime_error, "Incompatible Tensor shape for Mul Operation: {} for input#0 vs {} for input#1",
+                    inputsDims0, inputsDims1);
             }
             --out_id;
             --low_id;
@@ -53,9 +54,6 @@ bool Aidge::Mul_Op::forwardDims(bool /*allowDataDependency*/) {
         mOutputs[0]->resize(outDims);
         return true;
     }
-    else if (!getInput(0)->empty() && !getInput(1)->empty()) {
-        AIDGE_THROW_OR_ABORT(std::runtime_error, "Incompatible input dimensions for Operator Mul: {} and {}", getInput(0)->dims(), getInput(1)->dims());
-    }
 
     return false;
 }
diff --git a/src/operator/Pow.cpp b/src/operator/Pow.cpp
index 42715516e..135c79234 100644
--- a/src/operator/Pow.cpp
+++ b/src/operator/Pow.cpp
@@ -44,7 +44,8 @@ bool Aidge::Pow_Op::forwardDims(bool /*allowDataDependency*/) {
                 outDims[out_id] = lowDims[low_id];
             }
             else if ((lowDims[low_id] != 1) && (lowDims[low_id] != outDims[out_id])) {
-                AIDGE_THROW_OR_ABORT(std::runtime_error, "Unsupported Tensor shape for Pow Operation: {}", outDims);
+                AIDGE_THROW_OR_ABORT(std::runtime_error, "Incompatible Tensor shape for Pow Operation: {} for input#0 vs {} for input#1",
+                    inputsDims0, inputsDims1);
             }
             --out_id;
             --low_id;
diff --git a/src/operator/Sub.cpp b/src/operator/Sub.cpp
index 50e556ad9..b977f4ee7 100644
--- a/src/operator/Sub.cpp
+++ b/src/operator/Sub.cpp
@@ -46,7 +46,8 @@ bool Aidge::Sub_Op::forwardDims(bool /*allowDataDependency*/) {
                 outDims[out_id] = lowDims[low_id];
             }
             else if ((lowDims[low_id] != 1) && (lowDims[low_id] != outDims[out_id])) {
-                AIDGE_THROW_OR_ABORT(std::runtime_error, "Unsupported Tensor shape for Sub Operation: {}", outDims);
+                AIDGE_THROW_OR_ABORT(std::runtime_error, "Incompatible Tensor shape for Sub Operation: {} for input#0 vs {} for input#1",
+                    inputsDims0, inputsDims1);
             }
             --out_id;
             --low_id;
-- 
GitLab