diff --git a/include/aidge/data/Tensor.hpp b/include/aidge/data/Tensor.hpp index 9c72b597584521f8d4b0d35e66a2787b33a6c0fd..6718942360901bdf576eaa1a78830baf88dba2ec 100644 --- a/include/aidge/data/Tensor.hpp +++ b/include/aidge/data/Tensor.hpp @@ -347,6 +347,13 @@ class Tensor : public Data, */ Tensor mean() const; + /** + * @brief Element-wise clip operation for Tensor. + * @return Tensor + */ + Tensor clip(float min = std::numeric_limits<float>::lowest(), + float max = std::numeric_limits<float>::max()) const; + ~Tensor() noexcept; public: diff --git a/src/data/Tensor.cpp b/src/data/Tensor.cpp index b85bb472cb152509aaf33bba1f97fe55799a8ec7..407dab0fce435d1f5ddf81bebb9248c3a27a7977 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;