From c4ac13231a1e06ee2c1c4a038cf887cdde864a72 Mon Sep 17 00:00:00 2001
From: Antoni Olivier <olivier.antoni@cea.fr>
Date: Tue, 1 Apr 2025 16:29:51 +0200
Subject: [PATCH 1/2] Add clip method for Tensor

---
 include/aidge/data/Tensor.hpp |  6 ++++++
 src/data/Tensor.cpp           | 12 ++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/include/aidge/data/Tensor.hpp b/include/aidge/data/Tensor.hpp
index 9c72b5975..bfa17da10 100644
--- a/include/aidge/data/Tensor.hpp
+++ b/include/aidge/data/Tensor.hpp
@@ -347,6 +347,12 @@ class Tensor : public Data,
      */
     Tensor mean() const;
 
+	/**
+     * @brief Element-wise clip operation for Tensor.
+     * @return Tensor
+     */
+    Tensor clip(float min, float max) const;
+
     ~Tensor() noexcept;
 
 public:
diff --git a/src/data/Tensor.cpp b/src/data/Tensor.cpp
index b85bb472c..407dab0fc 100644
--- a/src/data/Tensor.cpp
+++ b/src/data/Tensor.cpp
@@ -24,6 +24,7 @@
 #include "aidge/operator/ReduceMean.hpp"
 #include "aidge/operator/Sub.hpp"
 #include "aidge/operator/Sqrt.hpp"
+#include "aidge/operator/Clip.hpp"
 #include "aidge/utils/Types.h"
 
 namespace Aidge {
@@ -240,6 +241,17 @@ Tensor Tensor::mean() const {
     return mean_.getOutput(0)->clone();
 }
 
+Tensor Tensor::clip(float min, float max) const {
+    AIDGE_ASSERT(hasImpl(), "Tensor has no implementation.");
+    auto clip_ = Clip_Op(min, max);
+    clip_.associateInput(0, std::make_shared<Tensor>(*this));
+    clip_.setDataType(dataType());
+    clip_.setDataFormat(dataFormat());
+    clip_.setBackend(mImpl->backend());
+    clip_.forward();
+    return clip_.getOutput(0)->clone();
+}
+
 // Tensor& Tensor::operator=(const Tensor& other) {
 //     if (this == &other) {
 //         return *this;
-- 
GitLab


From fb02e3ec799c8d504ac9b27d3d290234aafd254b Mon Sep 17 00:00:00 2001
From: Antoni Olivier <olivier.antoni@cea.fr>
Date: Tue, 1 Apr 2025 17:24:52 +0200
Subject: [PATCH 2/2] Add clip method for Tensor

---
 include/aidge/data/Tensor.hpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/aidge/data/Tensor.hpp b/include/aidge/data/Tensor.hpp
index bfa17da10..671894236 100644
--- a/include/aidge/data/Tensor.hpp
+++ b/include/aidge/data/Tensor.hpp
@@ -351,7 +351,8 @@ class Tensor : public Data,
      * @brief Element-wise clip operation for Tensor.
      * @return Tensor
      */
-    Tensor clip(float min, float max) const;
+    Tensor clip(float min = std::numeric_limits<float>::lowest(),
+                float max = std::numeric_limits<float>::max()) const;
 
     ~Tensor() noexcept;
 
-- 
GitLab