From dd27a4244322c805a6ffd653520e935346b31119 Mon Sep 17 00:00:00 2001
From: NAUD Maxence <maxence.naud@cea.fr>
Date: Fri, 1 Mar 2024 11:02:32 +0000
Subject: [PATCH] [Fix] Apply suggested changes - remove unused code in
 comments in ArrayHelpers.hpp - use std::unique_ptr<[]> instead of C style
 array in Test_Tensor - use AIDGE_THROW_OR_ABORT as a default implem for
 zeros() member function

---
 include/aidge/backend/TensorImpl.hpp |  2 +-
 include/aidge/utils/ArrayHelpers.hpp | 21 ---------------------
 unit_tests/data/Test_Tensor.cpp      | 10 ++++------
 3 files changed, 5 insertions(+), 28 deletions(-)

diff --git a/include/aidge/backend/TensorImpl.hpp b/include/aidge/backend/TensorImpl.hpp
index 08e976421..c363546f1 100644
--- a/include/aidge/backend/TensorImpl.hpp
+++ b/include/aidge/backend/TensorImpl.hpp
@@ -191,7 +191,7 @@ public:
      * @brief Set every element of the implementation to zero.
      */
     virtual void zeros() {
-        printf("Not implemented yet");
+        AIDGE_THROW_OR_ABORT(std::runtime_error, "Function not implented");
     }
 
     constexpr const char *backend() const { return mBackend; }
diff --git a/include/aidge/utils/ArrayHelpers.hpp b/include/aidge/utils/ArrayHelpers.hpp
index 3f241fa6a..b0db3ca11 100644
--- a/include/aidge/utils/ArrayHelpers.hpp
+++ b/include/aidge/utils/ArrayHelpers.hpp
@@ -103,32 +103,11 @@ constexpr std::array<T, N + 1> append(T t, std::array<T, N> a) {
 // Generic helper for initializing a Tensor
 template <typename T, std::size_t SIZE_0>
 struct Array1D {
-    // Array1D(std::initializer_list<T> list) {
-    //     auto it = list.begin();
-    //     for (std::size_t i = 0; i < SIZE_0; ++i, ++it) {
-    //         data[i] = *it;
-    //     }
-    // }
-    // Array1D(const T (&dataArray)[SIZE_0]) {
-    //     std::copy_n(&dataArray[0], SIZE_0, &data[0]);
-    // }
     T data[SIZE_0];
 };
 
 template <typename T, std::size_t SIZE_0, std::size_t SIZE_1>
 struct Array2D {
-    // Array2D(std::initializer_list<std::initializer_list<T>> list) {
-    //     auto it1 = list.begin();
-    //     for (std::size_t i = 0; i < SIZE_0; ++i, ++it1) {
-    //         auto it2 = it1->begin();
-    //         for (std::size_t j = 0; j < SIZE_1; ++j, ++it2) {
-    //             data[i][j] = *it2;
-    //         }
-    //     }
-    // }
-    // Array2D(const T (&dataArray)[SIZE_0][SIZE_1]) {
-    //     std::copy_n(&dataArray[0][0], SIZE_0 * SIZE_1, &data[0][0]);
-    // }
     T data[SIZE_0][SIZE_1];
 };
 
diff --git a/unit_tests/data/Test_Tensor.cpp b/unit_tests/data/Test_Tensor.cpp
index f26901dc3..12cd9840e 100644
--- a/unit_tests/data/Test_Tensor.cpp
+++ b/unit_tests/data/Test_Tensor.cpp
@@ -142,7 +142,7 @@ TEST_CASE("[core/data] Tensor(Construction)", "[Tensor][Constructor]") {
             Tensor T(Tdims);
 
             // file the tensor
-            float* array0 = new float[T.size()];
+            std::unique_ptr<float[]> array0(new float[T.size()]);
             for (std::size_t i = 0; i < T.size(); ++i) {
                 array0[i] = valueDist(gen);
             }
@@ -216,7 +216,7 @@ TEST_CASE("[core/data] Tensor(getter/setter)", "[Tensor][Getter][Setter]") {
         REQUIRE(T.strides() == Tstrides);
 
         // file the tensor
-        float* array0 = new float[T.size()];
+        std::unique_ptr<float[]> array0(new float[T.size()]);
         for (std::size_t i = 0; i < T.size(); ++i) {
             array0[i] = valueDist(gen);
         }
@@ -241,7 +241,6 @@ TEST_CASE("[core/data] Tensor(getter/setter)", "[Tensor][Getter][Setter]") {
         REQUIRE(T.get<float>(true_flatid) == 40.0f);
         REQUIRE(T.getImplOffset() == 0);
 
-        delete[] array0;
 
     //////////////
     // backend
@@ -279,12 +278,12 @@ TEST_CASE("[core/data] Tensor(other)", "[Tensor][extract][zeros][print]") {
             T.resize(Tdims);
 
             // file the tensor
-            float* array0 = new float[T.size()];
+            std::unique_ptr<float[]> array0(new float[T.size()]);
             for (std::size_t i = 0; i < T.size(); ++i) {
                 array0[i] = valueDist(gen);
             }
             T.setBackend("cpu");
-            T.getImpl() -> setRawPtr(array0, T.size());
+            T.getImpl() -> setRawPtr(array0.get(), T.size());
             float* res = static_cast<float*>(T.getImpl()->hostPtr());
             for (std::size_t i = 0; i < T.size(); ++i) {
                 REQUIRE(res[i] == array0[i]);
@@ -295,7 +294,6 @@ TEST_CASE("[core/data] Tensor(other)", "[Tensor][extract][zeros][print]") {
             for (std::size_t i = 0; i < T.size(); ++i) {
                 REQUIRE(res[i] == 0.0f);
             }
-            delete[] array0;
         }
     }
 
-- 
GitLab