From 50c7e9110ec67d8277a31f51799ab98cccde973a Mon Sep 17 00:00:00 2001 From: Olivier BICHLER <olivier.bichler@cea.fr> Date: Wed, 30 Aug 2023 14:37:23 +0200 Subject: [PATCH] Fixed using std::string for node name --- include/aidge/graph/GraphView.hpp | 2 +- include/aidge/graph/Node.hpp | 2 +- include/aidge/operator/AvgPooling.hpp | 4 ++-- include/aidge/operator/BatchNorm.hpp | 2 +- include/aidge/operator/Conv.hpp | 4 ++-- include/aidge/operator/ConvDepthWise.hpp | 4 ++-- include/aidge/operator/GenericOperator.hpp | 2 +- include/aidge/operator/Producer.hpp | 6 +++--- src/graph/GraphView.cpp | 6 +++--- src/graph/Node.cpp | 4 ++-- 10 files changed, 18 insertions(+), 18 deletions(-) diff --git a/include/aidge/graph/GraphView.hpp b/include/aidge/graph/GraphView.hpp index 718eddeaf..2e6323d70 100644 --- a/include/aidge/graph/GraphView.hpp +++ b/include/aidge/graph/GraphView.hpp @@ -217,7 +217,7 @@ public: * @return NodePtr returns a new empty node if the one asked for * was not found. */ - NodePtr getNode(const char *nodeName) const; + NodePtr getNode(const std::string& nodeName) const; /** * @brief Remove a Node from the current GraphView scope without affecting its connections. diff --git a/include/aidge/graph/Node.hpp b/include/aidge/graph/Node.hpp index f056505e6..11def52db 100644 --- a/include/aidge/graph/Node.hpp +++ b/include/aidge/graph/Node.hpp @@ -62,7 +62,7 @@ public: * @param op Operator giving the Node its number of connections. * @param name (optional) name for the Node. */ - Node(std::shared_ptr<Operator> op, const char *name = nullptr); + Node(std::shared_ptr<Operator> op, const std::string& name = ""); virtual ~Node() = default; diff --git a/include/aidge/operator/AvgPooling.hpp b/include/aidge/operator/AvgPooling.hpp index 7bf874087..bf76bd458 100644 --- a/include/aidge/operator/AvgPooling.hpp +++ b/include/aidge/operator/AvgPooling.hpp @@ -146,7 +146,7 @@ public: template <std::array<DimSize_t, 1>::size_type DIM> inline std::shared_ptr<Node> AvgPooling(const std::array<DimSize_t, DIM> &kernel_dims, - const char *name = nullptr, + const std::string& name = "", const std::array<DimSize_t, DIM> &stride_dims = create_array<DimSize_t,DIM>(1), const std::array<DimSize_t, (DIM<<1)> &padding_dims = create_array<DimSize_t,(DIM<<1)>(0)) { // FIXME: properly handle default w&b initialization in every cases @@ -158,7 +158,7 @@ inline std::shared_ptr<Node> AvgPooling(const std::array<DimSize_t, DIM> &kernel template <DimSize_t DIM> inline std::shared_ptr<Node> AvgPooling( DimSize_t const (&kernel_dims)[DIM], - const char *name = nullptr, + const std::string& name = "", const std::array<DimSize_t, DIM> &stride_dims = create_array<DimSize_t,DIM>(1), const std::array<DimSize_t, (DIM<<1)> &padding_dims = create_array<DimSize_t,(DIM<<1)>(0)) { static_assert(DIM<=MaxDim,"Too many kernel dimensions required by AvgPooling, not supported"); diff --git a/include/aidge/operator/BatchNorm.hpp b/include/aidge/operator/BatchNorm.hpp index 07af5fa84..6861c1359 100644 --- a/include/aidge/operator/BatchNorm.hpp +++ b/include/aidge/operator/BatchNorm.hpp @@ -144,7 +144,7 @@ public: template <DimSize_t DIM> inline std::shared_ptr<Node> BatchNorm(const float epsilon = 1.0e-5F, const float momentum = 0.1F, - const char *name = nullptr) { + const std::string& name = "") { static_assert(DIM<=MaxDim,"Too many kernel dimensions required by BatchNorm, not supported"); auto batchNorm = std::make_shared<Node>(std::make_shared<BatchNorm_Op<static_cast<DimIdx_t>(DIM)>>(epsilon, momentum), name); addProducer(batchNorm, 1, std::array<DimSize_t,0>({}), "scale"); diff --git a/include/aidge/operator/Conv.hpp b/include/aidge/operator/Conv.hpp index d6efba2ce..1edc94b96 100644 --- a/include/aidge/operator/Conv.hpp +++ b/include/aidge/operator/Conv.hpp @@ -166,7 +166,7 @@ template <std::array<DimSize_t, 1>::size_type DIM> inline std::shared_ptr<Node> Conv(DimSize_t in_channels, DimSize_t out_channels, const std::array<DimSize_t, DIM> &kernel_dims, - const char *name = nullptr, + const std::string& name = "", const std::array<DimSize_t, DIM> &stride_dims = create_array<DimSize_t,DIM>(1), const std::array<DimSize_t, (DIM<<1)> &padding_dims = create_array<DimSize_t,(DIM<<1)>(0), const std::array<DimSize_t, DIM> &dilation_dims = create_array<DimSize_t,DIM>(1)) { @@ -184,7 +184,7 @@ inline std::shared_ptr<Node> Conv( DimSize_t in_channels, DimSize_t out_channels, DimSize_t const (&kernel_dims)[DIM], - const char *name = nullptr, + const std::string& name = "", const std::array<DimSize_t, DIM> &stride_dims = create_array<DimSize_t,DIM>(1), const std::array<DimSize_t, (DIM<<1)> &padding_dims = create_array<DimSize_t,(DIM<<1)>(0), const std::array<DimSize_t, DIM> &dilation_dims = create_array<DimSize_t,DIM>(1)) { diff --git a/include/aidge/operator/ConvDepthWise.hpp b/include/aidge/operator/ConvDepthWise.hpp index a3b7fbf3b..95a2ff55b 100644 --- a/include/aidge/operator/ConvDepthWise.hpp +++ b/include/aidge/operator/ConvDepthWise.hpp @@ -165,7 +165,7 @@ class ConvDepthWise_Op : public Operator, template <std::array<DimSize_t, 1>::size_type DIM> inline std::shared_ptr<Node> ConvDepthWise(const std::array<DimSize_t, DIM> &kernel_dims, - const char *name = nullptr, + const std::string& name = "", const std::array<DimSize_t, DIM> &stride_dims = create_array<DimSize_t,DIM>(1), const std::array<DimSize_t, (DIM<<1)> &padding_dims = create_array<DimSize_t,(DIM<<1)>(0), const std::array<DimSize_t, DIM> &dilation_dims = create_array<DimSize_t,DIM>(1)) { @@ -180,7 +180,7 @@ inline std::shared_ptr<Node> ConvDepthWise(const std::array<DimSize_t, DIM> &ker template <DimSize_t DIM> inline std::shared_ptr<Node> ConvDepthWise( DimSize_t const (&kernel_dims)[DIM], - const char *name = nullptr, + const std::string& name = "", const std::array<DimSize_t, DIM> &stride_dims = create_array<DimSize_t,DIM>(1), const std::array<DimSize_t, (DIM<<1)> &padding_dims = create_array<DimSize_t,(DIM<<1)>(0), const std::array<DimSize_t, DIM> &dilation_dims = create_array<DimSize_t,DIM>(1)) { diff --git a/include/aidge/operator/GenericOperator.hpp b/include/aidge/operator/GenericOperator.hpp index a3e1f0291..dab5df9a8 100644 --- a/include/aidge/operator/GenericOperator.hpp +++ b/include/aidge/operator/GenericOperator.hpp @@ -158,7 +158,7 @@ class GenericOperator_Op * @return std::shared_ptr<Node> Node associated with the Generic Operator. */ inline std::shared_ptr<Node> GenericOperator(const char *type, IOIndex_t nbDataIn, IOIndex_t nbIn, IOIndex_t nbOut, - const char *name = nullptr) { + const std::string& name = "") { return std::make_shared<Node>(std::make_shared<GenericOperator_Op>(type, nbDataIn, nbIn, nbOut), name); } } // namespace Aidge diff --git a/include/aidge/operator/Producer.hpp b/include/aidge/operator/Producer.hpp index 2a2f8c053..acdc69b69 100644 --- a/include/aidge/operator/Producer.hpp +++ b/include/aidge/operator/Producer.hpp @@ -113,17 +113,17 @@ public: }; template <std::array<DimSize_t, 1>::size_type DIM> -inline std::shared_ptr<Node> Producer(const std::array<DimSize_t, DIM> &dims, const char *name = nullptr) { +inline std::shared_ptr<Node> Producer(const std::array<DimSize_t, DIM> &dims, const std::string& name = "") { static_assert(DIM<=MaxDim,"Too many tensor dimensions required by Producer, not supported"); return std::make_shared<Node>(std::make_shared<Producer_Op>(dims), name); } template <std::size_t DIM> -inline std::shared_ptr<Node> Producer(DimSize_t const (&dims)[DIM], const char *name = nullptr) { +inline std::shared_ptr<Node> Producer(DimSize_t const (&dims)[DIM], const std::string& name = "") { return Producer(to_array(dims), name); } -inline std::shared_ptr<Node> Producer(const std::shared_ptr<Tensor> tensor, const char *name = nullptr) { +inline std::shared_ptr<Node> Producer(const std::shared_ptr<Tensor> tensor, const std::string& name = "") { return std::make_shared<Node>(std::make_shared<Producer_Op>(tensor), name); } diff --git a/src/graph/GraphView.cpp b/src/graph/GraphView.cpp index ad412f5b8..a06410322 100644 --- a/src/graph/GraphView.cpp +++ b/src/graph/GraphView.cpp @@ -464,13 +464,13 @@ Aidge::GraphView::getChildren(const std::shared_ptr<Node> otherNode) const { std::shared_ptr<Aidge::Node> -Aidge::GraphView::getNode(const char *nodeName) const { +Aidge::GraphView::getNode(const std::string& nodeName) const { std::map<std::string, std::shared_ptr<Node>>::const_iterator it = - mNodeRegistry.find(std::string(nodeName)); + mNodeRegistry.find(nodeName); if (it != mNodeRegistry.end()) { return it->second; } else { - printf("No Node named %s in the current GraphView.\n", nodeName); + printf("No Node named %s in the current GraphView.\n", nodeName.c_str()); exit(-1); } } diff --git a/src/graph/Node.cpp b/src/graph/Node.cpp index b3db5befb..5fcc0e113 100644 --- a/src/graph/Node.cpp +++ b/src/graph/Node.cpp @@ -17,8 +17,8 @@ #include <vector> #include "aidge/utils/Types.h" -Aidge::Node::Node(std::shared_ptr<Operator> op, const char *name) - : mName((name == nullptr) ? std::string() : std::string(name)), +Aidge::Node::Node(std::shared_ptr<Operator> op, const std::string& name) + : mName(name), mOperator(op), mParents(std::vector<std::shared_ptr<Node>>(static_cast<std::size_t>(op->nbInputs()), nullptr)), mChildren(std::vector<std::vector<std::weak_ptr<Node>>>(static_cast<std::size_t>(op->nbOutputs()), -- GitLab