From 6fbf32e2917eb916dcc4889941029213a7281898 Mon Sep 17 00:00:00 2001
From: ls232920 <laurent.soulier@cea.fr>
Date: Fri, 6 Oct 2023 13:43:22 +0000
Subject: [PATCH] [FIX] fix for python binding only

---
 include/aidge/data/Tensor.hpp         |  9 +++++++++
 python_binding/data/pybind_Tensor.cpp |  4 +++-
 src/data/Tensor.cpp                   | 10 ++++++++++
 3 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/include/aidge/data/Tensor.hpp b/include/aidge/data/Tensor.hpp
index 4edd38567..aaf5b6e3d 100644
--- a/include/aidge/data/Tensor.hpp
+++ b/include/aidge/data/Tensor.hpp
@@ -488,6 +488,15 @@ public:
     /// @return Linear index of the first Byte_t of the data at given coordinates
     NbElts_t getIdx(std::vector<Coord_t> const &coordIdx) const noexcept;
 
+    /// @brief Get the logical coordinates of the data at given index, to be used only for
+    /// Python binding
+    /// @param coordIdx coordinates of the desired data
+    /// @note The index is expressed in number of elements
+    /// @return Logical coordinates of the data at given index
+    std::vector<Coord_t>
+    getCoordOnlyForPythonIfYoureUsingItYoureProbablyDoingSomethingWrong(
+        NbElts_t const flatIdx) const noexcept;
+
 private:
     /// @brief Getting the address of the very first data in memory (lexicographic
     /// order), read only access to data
diff --git a/python_binding/data/pybind_Tensor.cpp b/python_binding/data/pybind_Tensor.cpp
index 9cc8c33b5..3ad197245 100644
--- a/python_binding/data/pybind_Tensor.cpp
+++ b/python_binding/data/pybind_Tensor.cpp
@@ -91,7 +91,9 @@ void init_Tensor(py::module& m)
         .def("size", &Tensor::size)
         .def("resize", (void(Tensor::*)(const std::vector<DimSize_t>&)) & Tensor::resize)
         .def("has_impl", &Tensor::hasImpl)
-        .def("get_coord", &Tensor::getCoord)
+        .def(
+            "get_coord",
+            &Tensor::getCoordOnlyForPythonIfYoureUsingItYoureProbablyDoingSomethingWrong)
         .def("get_idx", &Tensor::getIdx)
         .def_static("get_available_backends", &Tensor::getAvailableBackends)
         .def("__str__", [](Tensor& b) { return b.toString(); })
diff --git a/src/data/Tensor.cpp b/src/data/Tensor.cpp
index 6f5806a74..1d3681db6 100644
--- a/src/data/Tensor.cpp
+++ b/src/data/Tensor.cpp
@@ -72,6 +72,16 @@ void Tensor::getCoord(
 {
     mImpl->getCoord(flatIdx, coordIdx);
 }
+
+std::vector<Coord_t>
+Tensor::getCoordOnlyForPythonIfYoureUsingItYoureProbablyDoingSomethingWrong(
+    NbElts_t const flatIdx) const noexcept
+{
+    std::vector<Coord_t> Coords(mDims.size());
+    getCoord(flatIdx, Coords);
+    return Coords;
+}
+
 NbElts_t Tensor::getIdx(std::vector<Coord_t> const &coordIdx) const noexcept
 {
     return mImpl->getIdx(coordIdx);
-- 
GitLab