From 40934b099b71f3158357f802068d5b10ed709320 Mon Sep 17 00:00:00 2001
From: SOULIER Laurent <laurent.soulier@cea.fr>
Date: Tue, 17 Oct 2023 14:47:18 +0200
Subject: [PATCH] [FIX] fixing some issues detected with msvc.

---
 include/aidge/data/Data.hpp                 |  9 +++++--
 include/aidge/data/Tensor.hpp               |  5 +++-
 include/aidge/utils/TensorUtils.hpp         |  2 +-
 python_binding/utils/pybind_TensorUtils.cpp | 30 +++++++++++----------
 4 files changed, 28 insertions(+), 18 deletions(-)

diff --git a/include/aidge/data/Data.hpp b/include/aidge/data/Data.hpp
index 5abac778b..47839a8be 100644
--- a/include/aidge/data/Data.hpp
+++ b/include/aidge/data/Data.hpp
@@ -233,13 +233,18 @@ constexpr std::size_t sizeOf(DataType const i_dataType)
     }
 }
 
+} // namespace detail
+} // namespace Aidge
+
+/// @todo possibly move all EnumStrings to Aidge::detail, see aidge#24
+namespace
+{
 template<>
 const char* const EnumStrings<Aidge::DataType>::data[]
     = {"Float64", "Float32", "Float16", "BFloat16", "Binary", "Ternary", "Int2",
        "Int3",    "Int4",    "Int5",    "Int6",     "Int7",   "Int8",    "Int16",
        "Int32",   "Int64",   "UInt2",   "UInt3",    "UInt4",  "UInt5",   "UInt6",
        "UInt7",   "UInt8",   "UInt16",  "UInt32",   "UInt64"};
-} // namespace detail
-} // namespace Aidge
 
+}
 #endif /* AIDGE_DATA_H_ */
\ No newline at end of file
diff --git a/include/aidge/data/Tensor.hpp b/include/aidge/data/Tensor.hpp
index caca9fbeb..9f28f216e 100644
--- a/include/aidge/data/Tensor.hpp
+++ b/include/aidge/data/Tensor.hpp
@@ -370,7 +370,10 @@ public:
      */
     inline DimIdx_t nbDims() const
     {
-        return mDims.size();
+        assert(
+            mDims.size() <= std::numeric_limits<DimIdx_t>::max()
+            && "Too many tensor dimensions");
+        return static_cast<DimIdx_t>(mDims.size());
     }
 
     /**
diff --git a/include/aidge/utils/TensorUtils.hpp b/include/aidge/utils/TensorUtils.hpp
index e14a6dced..66a197be9 100644
--- a/include/aidge/utils/TensorUtils.hpp
+++ b/include/aidge/utils/TensorUtils.hpp
@@ -46,7 +46,7 @@ bool approxEq(Aidge::Tensor t1, Aidge::Tensor t2, float relative, float absolute
     {
         return false;
     }
-    for (size_t i; i < t1.size(); ++i)
+    for (size_t i = 0; i < t1.size(); ++i)
     {
         if (static_cast<float>(std::abs(t1.get<T>(i) - t2.get<T>(i)))
             > (absolute + (relative * static_cast<float>(std::abs(t2.get<T>(i))))))
diff --git a/python_binding/utils/pybind_TensorUtils.cpp b/python_binding/utils/pybind_TensorUtils.cpp
index 78825a5f3..d51631758 100644
--- a/python_binding/utils/pybind_TensorUtils.cpp
+++ b/python_binding/utils/pybind_TensorUtils.cpp
@@ -18,17 +18,18 @@
 
 namespace py = pybind11;
 
-namespace Aidge {
-
-template<typename T>
-void addTensorUtilsFunction(py::module &m){
-    m.def("approx_eq",
-    & approxEq<T>,
-    py::arg("t1"),
-    py::arg("t2"),
-    py::arg("relative"),
-    py::arg("absolute"),
-    R"mydelimiter(
+namespace Aidge
+{
+template<typename T> void addTensorUtilsFunction(py::module &m)
+{
+    m.def(
+        "approx_eq",
+        &approxEq<T>,
+        py::arg("t1"),
+        py::arg("t2"),
+        py::arg("relative"),
+        py::arg("absolute"),
+        R"mydelimiter(
         Compare two :cpp:class:`Aidge::Tensor` value wise. The comparison function is:
             |t1-t2| <= absolute + relative * |t2|
 
@@ -48,10 +49,11 @@ void addTensorUtilsFunction(py::module &m){
         )mydelimiter");
 }
 
-void init_TensorUtils(py::module &m) {
+void init_TensorUtils(py::module &m)
+{
     addTensorUtilsFunction<float>(m);
     addTensorUtilsFunction<double>(m);
-    addTensorUtilsFunction<int>(m);
-    addTensorUtilsFunction<long>(m);
+    addTensorUtilsFunction<detail::CppType_t<DataType::Int32>>(m);
+    addTensorUtilsFunction<detail::CppType_t<DataType::Int64>>(m);
 }
 } // namespace Aidge
-- 
GitLab