From 78467ffe3883324fb11abe336e076031fd4ee3b6 Mon Sep 17 00:00:00 2001
From: ms245755 <michal.szczepanski@cea.fr>
Date: Wed, 22 May 2024 14:54:05 +0000
Subject: [PATCH] constructor fixed, add input producers to resize node

---
 include/aidge/operator/Resize.hpp | 65 +++++++++++++++++++++++--------
 1 file changed, 48 insertions(+), 17 deletions(-)

diff --git a/include/aidge/operator/Resize.hpp b/include/aidge/operator/Resize.hpp
index 04ce7731f..8c9698eb0 100644
--- a/include/aidge/operator/Resize.hpp
+++ b/include/aidge/operator/Resize.hpp
@@ -12,7 +12,6 @@
 #ifndef AIDGE_CORE_OPERATOR_Resize_H_
 #define AIDGE_CORE_OPERATOR_Resize_H_
 
-#include <cassert>
 #include <memory>
 #include <vector>
 
@@ -25,19 +24,36 @@
 
 namespace Aidge {
 
+enum class ResizeAttr { NoROI, NoScales, NoSizes };
+
 class Resize_Op : public OperatorTensor,
-                   public Registrable<Resize_Op, std::string, std::unique_ptr<OperatorImpl>(const Resize_Op&)>
-                   {
+                  public Registrable<Resize_Op, std::string, std::unique_ptr<OperatorImpl>(const Resize_Op&)>
+                  public StaticAttributes<ResizeAttr,
+                                          bool,
+                                          bool,
+                                          bool> {
 
 public:
-    static const std::string Type;  // du
+    static const std::string Type;
 
-    Resize_Op() : OperatorTensor(Type, 2, 0, 1) {}
-    //  4 input 0 attribute 1 output
-    // "data_input", "roi", "scales", "sizes"
+    Resize_Op() = delete;
     
+    using Attributes_ = StaticAttributes<ResizeAttr,
+                                          bool,
+                                          bool,
+                                          bool>;
+    template <ResizeAttr e>
+    using attr = typename Attributes_::template attr<e>;
+
+    constexpr Resize_Op(const bool noROI, const bool noScales, const bool noSizes)
+        : OperatorTensor(Type, 1, 3, 1),
+          // input tensor, onnx optional input [roi/scales/sizes] *constant, output
+          Attributes_(attr<ResizeAttr::NoROI>(    noROI),
+                      attr<ResizeAttr::NoScales>( noScales),
+                      attr<ResizeAttr::NoSizes>(  noSizes)) {}
     /**
-     * @brief Copy-constructor. Copy the operator attributes and its output tensor(s), but not its input tensors (the new operator has no input associated).
+     * @brief Copy-constructor. Copy the operator attributes and its output tensor(s),
+     * but not its input tensors (the new operator has no input associated).
      * @param op Operator to copy. 
      */
     Resize_Op(const Resize_Op& op)
@@ -63,13 +79,10 @@ public:
     // function see inputs
     bool forwardDims(bool allowDataDependency = false) override final;
 
-    void setBackend(const std::string& name, DeviceIdx_t device = 0) override final{
-    //     // to select which backend CUDA / CPU?
-    //     mImpl = Registrar<Resize_Op>::create(name)(*this);
-    //     mOutputs[0]->setBackend(name, device);
-    }
+    void setBackend(const std::string& name, DeviceIdx_t device = 0) override final;
 
     static const std::vector<std::string> getInputsName(){
+        //  roi, scales, sizes, even if considered as const parameters/input
         return {"data_input", "roi ", "scales", "sizes"};
     }
     static const std::vector<std::string> getOutputsName(){
@@ -77,11 +90,29 @@ public:
     }
 };
 
-//  WTF
-inline std::shared_ptr<Node> Resize(const std::string &name = "") {
-    // FIXME: properly handle default w&b initialization in every cases
-    return std::make_shared<Node>(std::make_shared<Resize_Op>(), name);
+inline std::shared_ptr<Node> Resize(const std::size_t   nbInputDims,
+                                    const bool          noROI, 
+                                    const bool          noScales,
+                                    const bool          noSizes,
+                                    const std::string &name = "") {
+    resize_node = std::make_shared<Node>(std::make_shared<Resize_Op>(noROI, noScales, noSizes), name);
+    // create empty producers of the same as the rank of input size [nbInputDims]
+    addProducer(resize_node, 1, std::array<DimSize_t, 1>({noROI ? 0     : nbInputDims}), "roi");    // already sets roi dims
+    addProducer(resize_node, 2, std::array<DimSize_t, 1>({noScales ? 0  : nbInputDims}), "scales"); // already sets scales dims
+    addProducer(resize_node, 3, std::array<DimSize_t, 1>({noSizes ? 0   : nbInputDims}), "sizes");  // already sets sizes dims
+    return resize_node;
 }
+
 }  // namespace Aidge
 
+namespace {
+template <>
+const char *const EnumStrings<Aidge::ResizeAttr>::data[] = {
+    "noROI",
+    "noScales", 
+    "noSizes"
+}; // do we keep it?
+}
+
+
 #endif /* AIDGE_CORE_OPERATOR_Resize_H_ */
-- 
GitLab