diff --git a/include/aidge/data/Tensor.hpp b/include/aidge/data/Tensor.hpp index 4edd385673b4743683c944a06cae5e59cbfaa94c..aaf5b6e3ddd92b64db9ef89c4cfa8b2f1d43b86f 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 9cc8c33b5dbfbeb5c93e5bb46da8d573d49a6f0a..3ad1972452501f5f79cce7bcec6c7ab8a0097579 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 6f5806a748c0b9c850eab2090970c7b7833dd3ed..1d3681db633bd8855a80de1f2227aa763d2294e4 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);