From 9b3579590d612d89cd36f42d47bb396670ef14af Mon Sep 17 00:00:00 2001 From: cmoineau <cyril.moineau@cea.fr> Date: Wed, 19 Feb 2025 09:57:29 +0000 Subject: [PATCH] Move declaration enumstring attr for clang compatibility. --- include/aidge/operator/ArgMax.hpp | 26 +++--- include/aidge/operator/AvgPooling.hpp | 26 +++--- include/aidge/operator/BatchNorm.hpp | 14 +-- include/aidge/operator/BitShift.hpp | 18 ++-- include/aidge/operator/Cast.hpp | 14 +-- include/aidge/operator/Clip.hpp | 21 +++-- include/aidge/operator/Concat.hpp | 24 ++--- include/aidge/operator/ConstantOfShape.hpp | 11 ++- include/aidge/operator/Conv.hpp | 31 ++++--- include/aidge/operator/ConvDepthWise.hpp | 30 +++--- include/aidge/operator/DepthToSpace.hpp | 13 +-- include/aidge/operator/Flatten.hpp | 13 +-- include/aidge/operator/Fold.hpp | 28 +++--- include/aidge/operator/Gather.hpp | 12 ++- include/aidge/operator/GridSample.hpp | 21 +++-- include/aidge/operator/Heaviside.hpp | 18 ++-- include/aidge/operator/LRN.hpp | 30 +++--- include/aidge/operator/LeakyReLU.hpp | 18 ++-- include/aidge/operator/MaxPooling.hpp | 19 ++-- include/aidge/operator/Memorize.hpp | 29 +++--- include/aidge/operator/Pad.hpp | 66 ++++++------- include/aidge/operator/Pop.hpp | 23 ++--- include/aidge/operator/Producer.hpp | 92 +++++++++---------- include/aidge/operator/ReduceMean.hpp | 21 +++-- include/aidge/operator/ReduceSum.hpp | 15 +-- include/aidge/operator/Reshape.hpp | 29 +++--- include/aidge/operator/Resize.hpp | 23 ++--- include/aidge/operator/Scaling.hpp | 25 ++--- include/aidge/operator/Shape.hpp | 20 ++-- include/aidge/operator/Slice.hpp | 14 +-- include/aidge/operator/Softmax.hpp | 20 ++-- include/aidge/operator/Split.hpp | 19 ++-- include/aidge/operator/Squeeze.hpp | 14 +-- include/aidge/operator/Stack.hpp | 19 ++-- include/aidge/operator/Transpose.hpp | 21 +++-- include/aidge/operator/Unfold.hpp | 31 ++++--- include/aidge/operator/Unsqueeze.hpp | 14 +-- include/aidge/operator/WeightInterleaving.hpp | 10 +- 38 files changed, 463 insertions(+), 429 deletions(-) diff --git a/include/aidge/operator/ArgMax.hpp b/include/aidge/operator/ArgMax.hpp index 6d24d87bd..bc97e1f5b 100644 --- a/include/aidge/operator/ArgMax.hpp +++ b/include/aidge/operator/ArgMax.hpp @@ -41,20 +41,28 @@ enum class ArgMaxAttr { */ SelectLastIndex }; - +} // namespace Aidge +/** + * @brief Provides string representations for the ArgMaxAttr enumeration. + */ +namespace { + template <> + const char *const EnumStrings<Aidge::ArgMaxAttr>::data[] = {"axis", "keep_dims", "select_last_index"}; +} +namespace Aidge { /** * @brief Description of the ArgMax operation on a Tensor. * * The ArgMax operation identifies the index of the maximum value along a specified axis of a Tensor. * - * The output of the ArgMax operation can retain the dimensionality of the input Tensor or reduce - * it by removing the specified axis. Additionally, in cases where multiple maximum values exist, + * The output of the ArgMax operation can retain the dimensionality of the input Tensor or reduce + * it by removing the specified axis. Additionally, in cases where multiple maximum values exist, * the user can specify whether to select the first or the last occurrence of the maximum value. * * Attributes: * - `Axis`: The axis along which the ArgMax operation is performed. For example, if the axis is `0`, * the operation is applied along rows; if it is `1`, it is applied along columns. - * - `KeepDims`: A boolean indicating whether to retain the reduced axis as a dimension of size `1` + * - `KeepDims`: A boolean indicating whether to retain the reduced axis as a dimension of size `1` * (`true`) or to completely remove it (`false`). * - `SelectLastIndex`: A boolean indicating how to handle ties (multiple maximum values along the axis): * - If `true`, the last index of the maximum value is selected. @@ -183,7 +191,7 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::ArgMaxAttr>::data; + return EnumStrings<Aidge::ArgMaxAttr>::data; } }; @@ -206,12 +214,6 @@ std::shared_ptr<Node> ArgMax(std::int32_t axis = 0, } // namespace Aidge -/** - * @brief Provides string representations for the ArgMaxAttr enumeration. - */ -namespace { -template <> -const char *const EnumStrings<Aidge::ArgMaxAttr>::data[] = {"axis", "keep_dims", "select_last_index"}; -} + #endif /* AIDGE_CORE_OPERATOR_ARGMAX_H_ */ diff --git a/include/aidge/operator/AvgPooling.hpp b/include/aidge/operator/AvgPooling.hpp index bd74dbdbf..c929e1b18 100644 --- a/include/aidge/operator/AvgPooling.hpp +++ b/include/aidge/operator/AvgPooling.hpp @@ -40,7 +40,18 @@ enum class AvgPoolingAttr { */ KernelDims }; - +} // namespace Aidge +namespace { + /** + * @brief String representation of the AvgPooling attributes. + */ + template <> + const char *const EnumStrings<Aidge::AvgPoolingAttr>::data[] = { + "stride_dims", + "kernel_dims" + }; +} +namespace Aidge { /** * @brief Class representing an Average Pooling operation. * @@ -181,7 +192,7 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::AvgPoolingAttr>::data; + return EnumStrings<Aidge::AvgPoolingAttr>::data; } }; @@ -224,15 +235,6 @@ extern template class Aidge::AvgPooling_Op<2>; extern template class Aidge::AvgPooling_Op<3>; extern template class Aidge::AvgPooling_Op<4>; -namespace { -/** - * @brief String representation of the AvgPooling attributes. - */ -template <> -const char *const EnumStrings<Aidge::AvgPoolingAttr>::data[] = { - "stride_dims", - "kernel_dims" -}; -} + #endif /* AIDGE_CORE_OPERATOR_AVGPOOLING_H_ */ diff --git a/include/aidge/operator/BatchNorm.hpp b/include/aidge/operator/BatchNorm.hpp index 995179d7f..3521c9b16 100644 --- a/include/aidge/operator/BatchNorm.hpp +++ b/include/aidge/operator/BatchNorm.hpp @@ -50,7 +50,12 @@ enum class BatchNormAttr { */ TrainingMode }; - +} // namespace Aidge +namespace { + template <> + const char *const EnumStrings<Aidge::BatchNormAttr>::data[] = { "epsilon", "momentum", "training_mode" }; +} +namespace Aidge { /** * @class BatchNorm_Op * @brief Implements the Batch Normalization (BN) operation, a technique used to normalize the inputs of a layer. @@ -158,7 +163,7 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::BatchNormAttr>::data; + return EnumStrings<Aidge::BatchNormAttr>::data; } }; @@ -178,9 +183,4 @@ extern template std::shared_ptr<Aidge::Node> Aidge::BatchNorm<2>(const DimSize_t extern template std::shared_ptr<Aidge::Node> Aidge::BatchNorm<3>(const DimSize_t, const float, const float, const bool, const std::string&); extern template std::shared_ptr<Aidge::Node> Aidge::BatchNorm<4>(const DimSize_t, const float, const float, const bool, const std::string&); -namespace { -template <> -const char *const EnumStrings<Aidge::BatchNormAttr>::data[] = { "epsilon", "momentum", "training_mode" }; -} - #endif /* AIDGE_CORE_OPERATOR_BATCHNORM_H_ */ diff --git a/include/aidge/operator/BitShift.hpp b/include/aidge/operator/BitShift.hpp index d066507dd..3e9f8c3f2 100644 --- a/include/aidge/operator/BitShift.hpp +++ b/include/aidge/operator/BitShift.hpp @@ -32,7 +32,15 @@ enum class BitShiftAttr { */ BitShiftdirection }; - +} +namespace { + /** + * @brief Specialization of `EnumStrings` for `BitShiftAttr`. + */ + template <> + const char* const EnumStrings<Aidge::BitShiftAttr>::data[] = {"bit_shift_direction"}; +} +namespace Aidge { /** * @class BitShift_Op * @brief A tensor operator to perform element-wise bitwise shift operations on tensors. @@ -169,12 +177,6 @@ inline std::shared_ptr<Node> BitShift(const BitShift_Op::BitShiftDirection direc } // namespace Aidge -namespace { -/** - * @brief Specialization of `EnumStrings` for `BitShiftAttr`. - */ -template <> -const char* const EnumStrings<Aidge::BitShiftAttr>::data[] = {"bit_shift_direction"}; -} + #endif /* AIDGE_CORE_OPERATOR_BITSHIFT_H_ */ diff --git a/include/aidge/operator/Cast.hpp b/include/aidge/operator/Cast.hpp index 12c3a280a..b2ffbb553 100644 --- a/include/aidge/operator/Cast.hpp +++ b/include/aidge/operator/Cast.hpp @@ -40,7 +40,12 @@ enum class CastAttr { */ TargetType }; - +} // namespace Aidge +namespace { + template <> + const char* const EnumStrings<Aidge::CastAttr>::data[] = { "target_type" }; +} +namespace Aidge { /** * @brief Description of the Cast operation to convert a tensor's data type. * @@ -143,7 +148,7 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::CastAttr>::data; + return EnumStrings<Aidge::CastAttr>::data; } }; @@ -157,9 +162,4 @@ std::shared_ptr<Node> Cast(const DataType targetType, const std::string& name = } // namespace Aidge -namespace { -template <> -const char* const EnumStrings<Aidge::CastAttr>::data[] = { "target_type" }; -} - #endif /* AIDGE_CORE_OPERATOR_CAST_H_ */ diff --git a/include/aidge/operator/Clip.hpp b/include/aidge/operator/Clip.hpp index 93c042d86..51ecb6eb3 100644 --- a/include/aidge/operator/Clip.hpp +++ b/include/aidge/operator/Clip.hpp @@ -33,14 +33,23 @@ enum class ClipAttr { Min, /**< Minimum value for clipping. */ Max /**< Maximum value for clipping. */ }; +} +namespace { + /** + * @brief Specialization of EnumStrings for ClipAttr. + */ + template <> + const char* const EnumStrings<Aidge::ClipAttr>::data[] = { "min", "max" }; +} +namespace Aidge { /** * @brief Description of the Clip operation to limit tensor values within a specified range. * * The Clip operator ensures tensor elements are within the range `[min, max]`. * - Values less than `min` are set to `min`. * - Values greater than `max` are set to `max`. - * + * * The input and output Tensors have the same dimensions. * * ### Attributes: @@ -154,7 +163,7 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::ClipAttr>::data; + return EnumStrings<Aidge::ClipAttr>::data; } }; @@ -173,12 +182,4 @@ std::shared_ptr<Aidge::Node> Clip( } // namespace Aidge -namespace { -/** - * @brief Specialization of EnumStrings for ClipAttr. - */ -template <> -const char* const EnumStrings<Aidge::ClipAttr>::data[] = { "min", "max" }; -} - #endif /* AIDGE_CORE_OPERATOR_CLIP_H_ */ diff --git a/include/aidge/operator/Concat.hpp b/include/aidge/operator/Concat.hpp index 7a4ea74a4..1f8a357a8 100644 --- a/include/aidge/operator/Concat.hpp +++ b/include/aidge/operator/Concat.hpp @@ -58,7 +58,17 @@ enum class ConcatAttr { */ Axis }; - +} // namespace Aidge +namespace { + /** + * @brief Specialization of EnumStrings for ConcatAttr. + */ + template <> + const char* const EnumStrings<Aidge::ConcatAttr>::data[] = { + "axis" + }; +} +namespace Aidge { /** * @class Concat_Op * @brief Implements the Concat operation to concatenate multiple tensors along a specified axis. @@ -175,7 +185,7 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::ConcatAttr>::data; + return EnumStrings<Aidge::ConcatAttr>::data; } }; @@ -190,14 +200,4 @@ std::shared_ptr<Node> Concat(const IOIndex_t nbIn, const std::int32_t axis = 0, } // namespace Aidge -namespace { -/** - * @brief Specialization of EnumStrings for ConcatAttr. - */ -template <> -const char* const EnumStrings<Aidge::ConcatAttr>::data[] = { - "axis" -}; -} - #endif /* AIDGE_CORE_OPERATOR_CONCAT_H_ */ diff --git a/include/aidge/operator/ConstantOfShape.hpp b/include/aidge/operator/ConstantOfShape.hpp index d837d108a..6176f69dd 100644 --- a/include/aidge/operator/ConstantOfShape.hpp +++ b/include/aidge/operator/ConstantOfShape.hpp @@ -40,6 +40,12 @@ enum class ConstantOfShapeAttr { Value, }; +namespace { + template <> + const char *const EnumStrings<Aidge::ConstantOfShapeAttr>::data[] = {"value"}; + } + + /** * @brief This operator's purpose is to generate a tensor of shape given via * input and filled with a given value set via attribute. @@ -135,10 +141,5 @@ inline std::shared_ptr<Node> ConstantOfShape(const Tensor value = Tensor(0.f), } } // namespace Aidge -namespace { -template <> -const char *const EnumStrings<Aidge::ConstantOfShapeAttr>::data[] = {"value"}; -} - #endif // AIDGE_CORE_OPERATOR_CONSTANT_OF_SHAPE_H_ diff --git a/include/aidge/operator/Conv.hpp b/include/aidge/operator/Conv.hpp index 7beea057e..135ff8860 100644 --- a/include/aidge/operator/Conv.hpp +++ b/include/aidge/operator/Conv.hpp @@ -40,15 +40,24 @@ enum class ConvAttr { DilationDims, // The dilation dimensions KernelDims // The kernel dimensions }; - +} // namespace Aidge +namespace { + template <> + const char *const EnumStrings<Aidge::ConvAttr>::data[] = { + "stride_dims", + "dilation_dims", + "kernel_dims" + }; +} +namespace Aidge { /** * @class Conv_Op * @brief Convolution operator for performing a multi-dimensional convolution. - * - * The Conv_Op class implements a convolution operator for tensors with customizable - * kernel dimensions, stride, and dilation values. The operator performs a convolution + * + * The Conv_Op class implements a convolution operator for tensors with customizable + * kernel dimensions, stride, and dilation values. The operator performs a convolution * operation on the input tensor and produces an output tensor. - * + * * ### Attributes: * - `strideDims`: Stride for each dimension of the input. * - `dilationDims`: Dilation for each dimension of the input. @@ -63,7 +72,7 @@ enum class ConvAttr { * - Stride dimensions: {1, 1} (stride of 1 in both height and width) * - Dilation dimensions: {1, 1} (no dilation) * - Padding: None - * - Output shape: + * - Output shape: * (1, 64, (32−3+2×0)/1+1, (32−3+2×0)/1+1) = (1, 64, 30, 30) * * @see OperatorTensor @@ -215,7 +224,7 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::ConvAttr>::data; + return EnumStrings<Aidge::ConvAttr>::data; } }; @@ -268,13 +277,5 @@ inline std::shared_ptr<Node> Conv( extern template class Aidge::Conv_Op<1>; extern template class Aidge::Conv_Op<2>; -namespace { -template <> -const char *const EnumStrings<Aidge::ConvAttr>::data[] = { - "stride_dims", - "dilation_dims", - "kernel_dims" -}; -} #endif /* AIDGE_CORE_OPERATOR_CONV_H_ */ diff --git a/include/aidge/operator/ConvDepthWise.hpp b/include/aidge/operator/ConvDepthWise.hpp index 3090b9feb..b307d67a6 100644 --- a/include/aidge/operator/ConvDepthWise.hpp +++ b/include/aidge/operator/ConvDepthWise.hpp @@ -34,15 +34,24 @@ enum class ConvDepthWiseAttr { DilationDims, // The dilation dimensions for the convolution. KernelDims // The kernel dimensions for the convolution. }; - +} // namespace Aidge +namespace { + template <> + const char *const EnumStrings<Aidge::ConvDepthWiseAttr>::data[] = { + "stride_dims", + "dilation_dims", + "kernel_dims" + }; +} +namespace Aidge { /** * @class ConvDepthWise_Op * @brief Depthwise Convolution operator for performing a multi-dimensional depthwise convolution. - * - * The ConvDepthWise_Op class implements a depthwise convolution operator for tensors with customizable - * kernel dimensions, stride, and dilation values. It performs a depthwise convolution operation on the + * + * The ConvDepthWise_Op class implements a depthwise convolution operator for tensors with customizable + * kernel dimensions, stride, and dilation values. It performs a depthwise convolution operation on the * input tensor and produces an output tensor. - * + * * ### Attributes: * - strideDims: Stride for each dimension of the input. * - dilationDims: Dilation for each dimension of the input. @@ -195,7 +204,7 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::ConvDepthWiseAttr>::data; + return EnumStrings<Aidge::ConvDepthWiseAttr>::data; } }; @@ -245,13 +254,4 @@ inline std::shared_ptr<Node> ConvDepthWise( extern template class Aidge::ConvDepthWise_Op<1>; extern template class Aidge::ConvDepthWise_Op<2>; -namespace { -template <> -const char *const EnumStrings<Aidge::ConvDepthWiseAttr>::data[] = { - "stride_dims", - "dilation_dims", - "kernel_dims" -}; -} - #endif /* AIDGE_CORE_OPERATOR_CONVDEPTHWISE_H_ */ diff --git a/include/aidge/operator/DepthToSpace.hpp b/include/aidge/operator/DepthToSpace.hpp index cc51ea180..c99f7bbb7 100644 --- a/include/aidge/operator/DepthToSpace.hpp +++ b/include/aidge/operator/DepthToSpace.hpp @@ -51,7 +51,12 @@ enum class DepthToSpaceAttr { BlockSize, /**< The block size for rearranging depth to spatial dimensions. */ Mode /**< The mode for depth-to-space transformation. */ }; - +} // namespace Aidge +namespace { + template <> + const char *const EnumStrings<Aidge::DepthToSpaceAttr>::data[] = { "block_size", "mode" }; +} +namespace Aidge{ /** * @class DepthToSpace_Op * @brief Represents the DepthToSpace operation to rearrange data from depth to spatial dimensions. @@ -170,7 +175,7 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::DepthToSpaceAttr>::data; + return EnumStrings<Aidge::DepthToSpaceAttr>::data; } }; @@ -187,9 +192,5 @@ std::shared_ptr<Node> DepthToSpace(const std::uint32_t blockSize, } // namespace Aidge -namespace { -template <> -const char *const EnumStrings<Aidge::DepthToSpaceAttr>::data[] = { "block_size", "mode" }; -} #endif //AIDGE_CORE_OPERATOR_DEPTHTOSPACE_H_ diff --git a/include/aidge/operator/Flatten.hpp b/include/aidge/operator/Flatten.hpp index 10ce58ad0..b61fc6912 100644 --- a/include/aidge/operator/Flatten.hpp +++ b/include/aidge/operator/Flatten.hpp @@ -54,7 +54,12 @@ enum class FlattenAttr { */ Axis }; - +} // namespace Aidge +namespace { + template <> + const char *const EnumStrings<Aidge::FlattenAttr>::data[] = { "axis" }; +} +namespace Aidge { /** * @brief Description the Flatten operation to reshape a tensor into a 2D matrix. * @@ -161,7 +166,7 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::FlattenAttr>::data; + return EnumStrings<Aidge::FlattenAttr>::data; } }; @@ -179,9 +184,5 @@ std::shared_ptr<Node> Flatten(std::int64_t axis = 1, const std::string &name = ""); } // namespace Aidge -namespace { -template <> -const char *const EnumStrings<Aidge::FlattenAttr>::data[] = { "axis" }; -} #endif /* AIDGE_CORE_OPERATOR_FLATTEN_H_ */ diff --git a/include/aidge/operator/Fold.hpp b/include/aidge/operator/Fold.hpp index 9d2d4e0df..2f9974e8e 100644 --- a/include/aidge/operator/Fold.hpp +++ b/include/aidge/operator/Fold.hpp @@ -64,7 +64,17 @@ enum class FoldAttr { */ KernelDims }; - +} // namespace Aidge +namespace { + template <> + const char* const EnumStrings<Aidge::FoldAttr>::data[] = { + "output_dims", + "stride_dims", + "dilation_dims", + "kernel_dims" + }; +} +namespace Aidge { /** * @class Fold_Op * @brief Implements the Fold operation to combine or transform tensor dimensions. @@ -82,7 +92,7 @@ enum class FoldAttr { * output height (out_h) = floor((input height - kernel height) / stride height) + 1 * output width (out_w) = floor((input width - kernel width) / stride width) + 1 * - The exact output shape will depend on these calculations for each spatial dimension (height, width) and the number of output channels. - * + * * @example: * - Input shape: (1, 16, 32, 32) // Batch size: 1, Channels: 16, Height: 32, Width: 32 * - Kernel dimensions: (3, 3) // 3x3 kernel @@ -216,13 +226,13 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::FoldAttr>::data; + return EnumStrings<Aidge::FoldAttr>::data; } }; /** * @brief Create a Fold operation node. - * + * * This function creates a Fold operation node that applies a fold transformation * to a tensor based on the specified attributes. * @@ -255,14 +265,4 @@ extern template class Aidge::Fold_Op<2>; } // namespace Aidge -namespace { -template <> -const char* const EnumStrings<Aidge::FoldAttr>::data[] = { - "output_dims", - "stride_dims", - "dilation_dims", - "kernel_dims" -}; -} - #endif /* AIDGE_CORE_OPERATOR_FOLD_H_ */ diff --git a/include/aidge/operator/Gather.hpp b/include/aidge/operator/Gather.hpp index 3842a041e..86fc7bc78 100644 --- a/include/aidge/operator/Gather.hpp +++ b/include/aidge/operator/Gather.hpp @@ -61,6 +61,12 @@ enum class GatherAttr { GatheredShape }; +} // namespace Aidge +namespace { + template <> + const char *const EnumStrings<Aidge::GatherAttr>::data[] = {"axis", "indices", "gathered_shape"}; +} +namespace Aidge { /** * @brief Description for the Gather operation on an input tensor. * @@ -190,7 +196,7 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::GatherAttr>::data; + return EnumStrings<Aidge::GatherAttr>::data; } }; @@ -213,9 +219,5 @@ std::shared_ptr<Node> Gather(std::int8_t axis = 0, } // namespace Aidge -namespace { -template <> -const char *const EnumStrings<Aidge::GatherAttr>::data[] = {"axis", "indices", "gathered_shape"}; -} #endif /* AIDGE_CORE_OPERATOR_GATHER_H_ */ diff --git a/include/aidge/operator/GridSample.hpp b/include/aidge/operator/GridSample.hpp index 28c5fb5e5..066422311 100644 --- a/include/aidge/operator/GridSample.hpp +++ b/include/aidge/operator/GridSample.hpp @@ -29,6 +29,16 @@ enum class GridSampleAttr { PaddingMode, // Specifies how to handle out-of-boundary grid values. AlignCorners // Determines whether grid values are normalized to align with the image corners. }; +} // namespace Aidge +namespace { + template <> + const char* const EnumStrings<Aidge::GridSampleAttr>::data[] = { + "mode", + "padding_mode", + "align_corners" + }; +} +namespace Aidge { /** * @class GridSample_Op @@ -176,7 +186,7 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::GridSampleAttr>::data; + return EnumStrings<Aidge::GridSampleAttr>::data; } }; @@ -197,13 +207,4 @@ std::shared_ptr<Node> GridSample( } // namespace Aidge -namespace { -template <> -const char* const EnumStrings<Aidge::GridSampleAttr>::data[] = { - "mode", - "padding_mode", - "align_corners" -}; -} - #endif /* AIDGE_CORE_OPERATOR_GRIDSAMPLE_H_ */ diff --git a/include/aidge/operator/Heaviside.hpp b/include/aidge/operator/Heaviside.hpp index 874853c4e..806ed47f3 100644 --- a/include/aidge/operator/Heaviside.hpp +++ b/include/aidge/operator/Heaviside.hpp @@ -31,6 +31,15 @@ enum class HeavisideAttr { */ Value }; +} // namespace Aidge +namespace { + /** + * @brief Define string representations for Heaviside attributes. + */ + template <> + const char *const EnumStrings<Aidge::HeavisideAttr>::data[] = {"value"}; +} +namespace Aidge { /** * @class Heaviside_Op @@ -115,7 +124,7 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::HeavisideAttr>::data; + return EnumStrings<Aidge::HeavisideAttr>::data; } /** @@ -149,12 +158,5 @@ std::shared_ptr<Node> Heaviside(float value, const std::string &name = ""); } // namespace Aidge -namespace { -/** - * @brief Define string representations for Heaviside attributes. - */ -template <> -const char *const EnumStrings<Aidge::HeavisideAttr>::data[] = {"value"}; -} #endif /* AIDGE_CORE_OPERATOR_HEAVISIDE_H_ */ diff --git a/include/aidge/operator/LRN.hpp b/include/aidge/operator/LRN.hpp index 9019c089b..6c82b6b46 100644 --- a/include/aidge/operator/LRN.hpp +++ b/include/aidge/operator/LRN.hpp @@ -30,20 +30,28 @@ enum class LRNAttr { Bias, ///< Constant bias added to the normalization term. Size ///< Number of channels to normalize over. }; - +} // namespace Aidge +namespace { + /** + * @brief EnumStrings specialization for LRNAttr. + */ + template <> + const char *const EnumStrings<Aidge::LRNAttr>::data[] = {"alpha", "beta", "bias", "size", nullptr}; +} +namespace Aidge { /** * @brief Description of a Local Response Normalization (LRN) operation on an input Tensor. * - * LRN is a normalization technique that applies across channels in a local region - * to enhance generalization and promote competition between neurons. It is commonly + * LRN is a normalization technique that applies across channels in a local region + * to enhance generalization and promote competition between neurons. It is commonly * used in Convolutional Neural Networks (CNNs). * * For each element x in the input Tensor, the function is defined as: * `f(x) = x / (bias + alpha * sum(x_i^2))^beta`, where: * - `x` is the current element being normalized. - * - The summation `sum(x_i^2)` is taken over a local region of `size` channels + * - The summation `sum(x_i^2)` is taken over a local region of `size` channels * surrounding `x` (both before and after the current channel, if available). - * - `bias`, `alpha`, and `beta` are scalar hyperparameters controlling the + * - `bias`, `alpha`, and `beta` are scalar hyperparameters controlling the * normalization behavior. * * Parameters: @@ -52,7 +60,7 @@ enum class LRNAttr { * - `alpha`: A scaling factor for the squared sum of elements in the local region. * - `beta`: The exponent applied to the normalization term. * - * The input and output Tensors have the same shape. If the input Tensor has shape `(N, C, H, W)`, + * The input and output Tensors have the same shape. If the input Tensor has shape `(N, C, H, W)`, * the output Tensor will also have shape `(N, C, H, W)`. * * @see OperatorTensor @@ -164,7 +172,7 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::LRNAttr>::data; + return EnumStrings<Aidge::LRNAttr>::data; } }; @@ -179,12 +187,4 @@ std::shared_ptr<Node> LRN(std::int32_t size, const std::string& name = ""); } // namespace Aidge -namespace { -/** - * @brief EnumStrings specialization for LRNAttr. - */ -template <> -const char *const EnumStrings<Aidge::LRNAttr>::data[] = {"alpha", "beta", "bias", "size", nullptr}; -} - #endif /* AIDGE_CORE_OPERATOR_LRN_H_ */ diff --git a/include/aidge/operator/LeakyReLU.hpp b/include/aidge/operator/LeakyReLU.hpp index 5381b3cb1..acf9bae7f 100644 --- a/include/aidge/operator/LeakyReLU.hpp +++ b/include/aidge/operator/LeakyReLU.hpp @@ -30,7 +30,13 @@ enum class LeakyReLUAttr { */ NegativeSlope }; - +} // namespace Aidge +namespace { + template <> + const char* const EnumStrings<Aidge::LeakyReLUAttr>::data[] + = {"negative_slope"}; + } +namespace Aidge{ /** * @class LeakyReLU_Op * @brief Implements the LeakyReLU activation function. @@ -77,7 +83,7 @@ public: /** * @brief Copy-constructor. * @param[in] op LeakyReLU_Op to copy. - * @details Copies the operator attributes and its output tensor(s), but not its input tensors. + * @details Copies the operator attributes and its output tensor(s), but not its input tensors. * The new operator has no associated input. */ LeakyReLU_Op(const LeakyReLU_Op& op); @@ -121,7 +127,7 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::LeakyReLUAttr>::data; + return EnumStrings<Aidge::LeakyReLUAttr>::data; } }; @@ -135,10 +141,4 @@ public: std::shared_ptr<Node> LeakyReLU(float negativeSlope = 0.0f, const std::string& name = ""); } -namespace { -template <> -const char* const EnumStrings<Aidge::LeakyReLUAttr>::data[] - = {"negative_slope"}; -} - #endif /* AIDGE_CORE_OPERATOR_LEAKYRELU_H_ */ diff --git a/include/aidge/operator/MaxPooling.hpp b/include/aidge/operator/MaxPooling.hpp index 11b3ace26..6105fe12c 100644 --- a/include/aidge/operator/MaxPooling.hpp +++ b/include/aidge/operator/MaxPooling.hpp @@ -56,6 +56,16 @@ enum class MaxPoolingAttr { */ CeilMode, }; +} // namespace Aidge +namespace { + /** + * @brief String representations of MaxPooling attributes for debugging and logging. + */ + template <> + const char *const EnumStrings<Aidge::MaxPoolingAttr>::data[] = {"stride_dims", "kernel_dims", "ceil_mode"}; + } + +namespace Aidge{ /** * @class MaxPooling_Op @@ -188,7 +198,7 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::MaxPoolingAttr>::data; + return EnumStrings<Aidge::MaxPoolingAttr>::data; } }; @@ -235,12 +245,5 @@ inline std::shared_ptr<Node> MaxPooling( } // namespace Aidge -namespace { -/** - * @brief String representations of MaxPooling attributes for debugging and logging. - */ -template <> -const char *const EnumStrings<Aidge::MaxPoolingAttr>::data[] = {"stride_dims", "kernel_dims", "ceil_mode"}; -} #endif /* AIDGE_CORE_OPERATOR_MAXPOOLING_H_ */ diff --git a/include/aidge/operator/Memorize.hpp b/include/aidge/operator/Memorize.hpp index 10bbfce85..59df17ec1 100644 --- a/include/aidge/operator/Memorize.hpp +++ b/include/aidge/operator/Memorize.hpp @@ -120,10 +120,22 @@ enum class MemorizeAttr { ForwardStep, // Tracks the current step in the forward pass. EndStep // The final step for which memory updates will occur. }; - +} // namespace Aidge +namespace { + /** + * @brief String representations of the Memorize operator's attributes. + */ + template <> + const char *const EnumStrings<Aidge::MemorizeAttr>::data[] = { + "schedule_step", + "forward_step", + "end_step" + }; +} +namespace Aidge { /** * @class Memorize_Op - * @brief The Memorize Operator is responsible for storing a tensor's state over a defined + * @brief The Memorize Operator is responsible for storing a tensor's state over a defined * number of iterations and providing the stored value as output at each iteration. * * Memorize operators are used in models with recurrent structures or feedback loops, such as LSTMs. @@ -246,7 +258,7 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::MemorizeAttr>::data; + return EnumStrings<Aidge::MemorizeAttr>::data; } }; @@ -259,16 +271,5 @@ public: std::shared_ptr<Node> Memorize(const std::uint32_t endStep, const std::string& name = ""); } // namespace Aidge -namespace { -/** - * @brief String representations of the Memorize operator's attributes. - */ -template <> -const char *const EnumStrings<Aidge::MemorizeAttr>::data[] = { - "schedule_step", - "forward_step", - "end_step" -}; -} #endif /* AIDGE_CORE_OPERATOR_MEMORIZE_H_ */ diff --git a/include/aidge/operator/Pad.hpp b/include/aidge/operator/Pad.hpp index 417e9664c..de7c3d2b2 100644 --- a/include/aidge/operator/Pad.hpp +++ b/include/aidge/operator/Pad.hpp @@ -36,6 +36,18 @@ enum class PadAttr { BorderValue ///< Value to be used for constant padding. }; +namespace { + /** + * @brief EnumStrings specialization for PadAttr. + */ + template <> + const char* const EnumStrings<Aidge::PadAttr>::data[] = { + "begin_end_borders", + "border_type", + "border_value" + }; +} // namespace + /** * @enum PadBorderType * @brief Types of border handling available for padding. @@ -47,7 +59,19 @@ enum class PadBorderType { Wrap, ///< Values wrap around the tensor dimensions. Zero ///< All out-of-bound values are set to 0. }; - +} // namespace Aidge +/** + * @brief EnumStrings specialization for PadBorderType. + */ +template <> +const char* const EnumStrings<Aidge::PadBorderType>::data[] = { + "Constant", + "Edge", + "Reflect", + "Wrap", + "Zero" +}; +namespace Aidge { /** * @class Pad_Op * @brief Implementation of the Pad operator. @@ -64,14 +88,14 @@ enum class PadBorderType { * The operator supports various border handling techniques (e.g., constant padding, reflection, wrapping). * * ### Output Tensor Shape: - * If the input tensor has a shape `[B, C, d1, d2, ..., dN]`, where `B` is the batch size, - * `C` is the number of channels, and `[d1, d2, ..., dN]` are the spatial dimensions, - * and the padding is defined by `beginEndTuples = {b1, e1, b2, e2, ..., bN, eN}`, + * If the input tensor has a shape `[B, C, d1, d2, ..., dN]`, where `B` is the batch size, + * `C` is the number of channels, and `[d1, d2, ..., dN]` are the spatial dimensions, + * and the padding is defined by `beginEndTuples = {b1, e1, b2, e2, ..., bN, eN}`, * the output tensor shape will be: - * + * * `[B, C, d1 + b1 + e1, d2 + b2 + e2, ..., dN + bN + eN]`. - * - * The padding values `b_i` and `e_i` specify the number of elements to add before and after + * + * The padding values `b_i` and `e_i` specify the number of elements to add before and after * the corresponding spatial dimension `d_i`. Batch size and channel count remain unchanged. * * @example Constant Padding: @@ -92,7 +116,7 @@ enum class PadBorderType { * - Output tensor shape: `[B, C, 4 + 1 + 1, 5 + 2 + 2, 6 + 0 + 0] = [B, C, 6, 9, 6]` * - Padding values mirror the existing tensor values. * - * This operator is commonly used for image processing, extending spatial dimensions while maintaining + * This operator is commonly used for image processing, extending spatial dimensions while maintaining * batch and channel consistency, or aligning tensor dimensions in machine learning workflows. */ template <DimIdx_t DIM> @@ -222,7 +246,7 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::PadAttr>::data; + return EnumStrings<Aidge::PadAttr>::data; } }; @@ -258,30 +282,6 @@ inline std::shared_ptr<Node> Pad( extern template class Aidge::Pad_Op<1>; extern template class Aidge::Pad_Op<2>; -namespace { - -/** - * @brief EnumStrings specialization for PadAttr. - */ -template <> -const char* const EnumStrings<Aidge::PadAttr>::data[] = { - "begin_end_borders", - "border_type", - "border_value" -}; -/** - * @brief EnumStrings specialization for PadBorderType. - */ -template <> -const char* const EnumStrings<Aidge::PadBorderType>::data[] = { - "Constant", - "Edge", - "Reflect", - "Wrap", - "Zero" -}; - -} // namespace #endif /* AIDGE_CORE_OPERATOR_PAD_H_ */ diff --git a/include/aidge/operator/Pop.hpp b/include/aidge/operator/Pop.hpp index 08d40ba79..3d9b97933 100644 --- a/include/aidge/operator/Pop.hpp +++ b/include/aidge/operator/Pop.hpp @@ -95,7 +95,17 @@ public: enum class PopAttr { ForwardStep // Tracks the current step in the forward pass }; - +} // namespace Aidge +namespace { + /** + * @brief String representations of the `Pop` operator's attributes. + */ + template <> + const char *const EnumStrings<Aidge::PopAttr>::data[] = { + "forward_step" + }; +} +namespace Aidge { /** * @class Pop_Op * @brief The `Pop` operator is responsible for removing and outputting elements from a data structure. @@ -204,7 +214,7 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::PopAttr>::data; + return EnumStrings<Aidge::PopAttr>::data; } }; @@ -216,14 +226,5 @@ public: std::shared_ptr<Node> Pop(const std::string& name = ""); } // namespace Aidge -namespace { -/** - * @brief String representations of the `Pop` operator's attributes. - */ -template <> -const char *const EnumStrings<Aidge::PopAttr>::data[] = { - "forward_step" -}; -} #endif /* AIDGE_CORE_OPERATOR_POP_H_ */ diff --git a/include/aidge/operator/Producer.hpp b/include/aidge/operator/Producer.hpp index 1d6b96582..3690579d3 100644 --- a/include/aidge/operator/Producer.hpp +++ b/include/aidge/operator/Producer.hpp @@ -35,25 +35,33 @@ namespace Aidge { * @brief Attributes specific to the `Producer_Op` class. */ enum class ProdAttr { Constant }; - +} // namespace Aidge +namespace { + /** + * @brief Enum string representation for `ProdAttr`. + */ + template <> + const char* const EnumStrings<Aidge::ProdAttr>::data[] = {"constant"}; +} +namespace Aidge { /** * @class Producer_Op * @brief Represents an operator that stores a tensor in memory and provides it as an output. - * - * The `Producer_Op` class is a specialized operator designed to store a tensor in memory - * and return it as an output tensor. It is typically used to store parameters or input - * values for a computational graph. A `Producer_Op` does not have any input data, parameters, - * or attributes, making it a fundamental building block for constant or initialized values + * + * The `Producer_Op` class is a specialized operator designed to store a tensor in memory + * and return it as an output tensor. It is typically used to store parameters or input + * values for a computational graph. A `Producer_Op` does not have any input data, parameters, + * or attributes, making it a fundamental building block for constant or initialized values * within the graph. - * + * * Key characteristics of a `Producer_Op`: * - No inputs: The operator does not accept any input tensors. * - No parameters or attributes: It is solely responsible for producing an output tensor. * - Stores and returns a tensor: The stored tensor is accessible as the operator's output. - * - * This operator is useful for scenarios where fixed or pre-initialized tensors need to + * + * This operator is useful for scenarios where fixed or pre-initialized tensors need to * be introduced into a graph, such as weights, biases, or constant values. - * + * * @see OperatorTensor * @see Registrable */ @@ -77,7 +85,7 @@ public: /** * @brief Constructs a `Producer_Op` object with specific dimensions. - * + * * @tparam DIM The number of dimensions for the tensor. * @param[in] dims Array defining the dimensions of the tensor. * @param[in] constant Indicates whether the tensor is constant. @@ -87,7 +95,7 @@ public: /** * @brief Constructs a `Producer_Op` object from an existing tensor. - * + * * @param[in] tensor A shared pointer to the tensor to be produced. * @param[in] constant Indicates whether the tensor should be constant. */ @@ -95,10 +103,10 @@ public: /** * @brief Copy constructor. - * - * Copies the attributes and output tensors of the operator. + * + * Copies the attributes and output tensors of the operator. * Input tensors are not copied, and the new operator will have no associated inputs. - * + * * @param[in] op The `Producer_Op` object to copy. */ Producer_Op(const Producer_Op& op); @@ -106,28 +114,28 @@ public: public: /** * @brief Conversion operator to retrieve the output tensor. - * + * * @return A shared pointer to the output tensor. */ operator std::shared_ptr<Tensor>() const { return mOutputs[0]; } /** * @brief Clones the operator using the copy constructor. - * + * * @return A shared pointer to the cloned operator. */ std::shared_ptr<Operator> clone() const override; /** * @brief Retrieves the dimensions of the output tensor. - * + * * @return A vector containing the dimensions of the output tensor. */ inline const std::vector<DimSize_t> dims() const noexcept { return mOutputs[0]->dims(); } /** * @brief Sets the backend for the operator's execution. - * + * * @param[in] name The name of the backend. * @param[in] device The device index (default is 0). */ @@ -135,35 +143,35 @@ public: /** * @brief Retrieves the list of available backends for this operator. - * + * * @return A set containing the names of available backends. */ std::set<std::string> getAvailableBackends() const override; /** * @brief Retrieves the operator's attributes. - * + * * @return A shared pointer to the operator's attributes. */ inline std::shared_ptr<Attributes> attributes() const override { return mAttributes; } /** * @brief Retrieves the constant attribute. - * + * * @return A reference to the constant attribute. */ inline bool& constant() const { return mAttributes->template getAttr<ProdAttr::Constant>(); } /** * @brief Performs the forward operation for the operator. - * + * * Generates the output tensor based on the defined attributes and configuration. */ void forward() override final; /** * @brief Placeholder for the backward operation. - * + * * This function logs a debug message, as `Producer_Op` typically does not support backpropagation. */ void backward() override final { @@ -172,12 +180,12 @@ public: /** * @brief Associates an input tensor with the operator. - * + * * This operation is not supported by `Producer_Op` as it does not take inputs. - * + * * @param[in] inputIdx The index of the input. * @param[in] data A shared pointer to the data to associate. - * + * * @throws std::runtime_error Always throws, as inputs are not supported. */ void associateInput(const IOIndex_t /*inputIdx*/, const std::shared_ptr<Data>& /*data*/) override final { @@ -186,35 +194,35 @@ public: /** * @brief Checks whether dimensions are forwarded. - * + * * @return Always true for `Producer_Op`. */ inline bool forwardDims(bool /*allowDataDependency*/ = false) override final { return true; } /** * @brief Confirms that dimensions have been forwarded. - * + * * @return Always true for `Producer_Op`. */ inline bool dimsForwarded() const noexcept override final { return true; } /** * @brief Retrieves the names of the inputs for the operator. - * + * * @return An empty vector, as `Producer_Op` takes no inputs. */ static const std::vector<std::string> getInputsName() { return {}; } /** * @brief Retrieves the names of the outputs for the operator. - * + * * @return A vector containing the output name "data_output". */ static const std::vector<std::string> getOutputsName() { return {"data_output"}; } /** * @brief Sets the output tensor for the operator. - * + * * @param[in] outputIdx Index of the output to set. * @param[in] data A shared pointer to the data. */ @@ -223,12 +231,12 @@ public: /** * @brief Helper function to create a producer node with specified dimensions. - * + * * @tparam DIM The number of dimensions. * @param[in] dims Array defining the dimensions of the tensor. * @param[in] name Optional name for the node. * @param[in] constant Indicates whether the tensor should be constant. - * + * * @return A shared pointer to the created node. */ template <std::size_t DIM> @@ -236,11 +244,11 @@ std::shared_ptr<Node> Producer(const std::array<DimSize_t, DIM>& dims, const std /** * @brief Helper function with a C-style array for dimension deduction. - * + * * @param[in] dims C-style array defining the tensor dimensions. * @param[in] name Optional name for the node. * @param[in] constant Indicates whether the tensor should be constant. - * + * * @return A shared pointer to the created node. */ template <std::size_t DIM> @@ -257,12 +265,12 @@ std::shared_ptr<Node> addProducer(std::shared_ptr<Node>& otherNode, /** * @brief Adds a producer node to another node with a C-style array. - * + * * @param[in] otherNode The node to associate with the producer. * @param[in] inputIdx The input index. * @param[in] dims C-style array defining the tensor dimensions. * @param[in] extension An extension string for the producer. - * + * * @return A shared pointer to the updated node. */ template <std::size_t DIM> @@ -272,12 +280,4 @@ std::shared_ptr<Node> addProducer(std::shared_ptr<Node>& otherNode, const IOInde } // namespace Aidge -namespace { -/** - * @brief Enum string representation for `ProdAttr`. - */ -template <> -const char* const EnumStrings<Aidge::ProdAttr>::data[] = {"constant"}; -} - #endif /* AIDGE_CORE_OPERATOR_PRODUCER_H_ */ diff --git a/include/aidge/operator/ReduceMean.hpp b/include/aidge/operator/ReduceMean.hpp index c6d875719..3ee4a1bec 100644 --- a/include/aidge/operator/ReduceMean.hpp +++ b/include/aidge/operator/ReduceMean.hpp @@ -51,7 +51,16 @@ enum class ReduceMeanAttr { */ NoopWithEmptyAxes }; - +} // namespace Aidge +namespace { + template <> + const char *const EnumStrings<Aidge::ReduceMeanAttr>::data[] = { + "axes", + "keep_dims", + "noop_with_empty_axes" + }; +} +namespace Aidge { /** * @class ReduceMean_Op * @brief Implements the ReduceMean operation to compute the mean of a tensor along specified axes. @@ -170,7 +179,7 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::ReduceMeanAttr>::data; + return EnumStrings<Aidge::ReduceMeanAttr>::data; } virtual ~ReduceMean_Op() noexcept; @@ -194,13 +203,5 @@ std::shared_ptr<Node> ReduceMean(const std::vector<std::int32_t> &axes, } // namespace Aidge -namespace { -template <> -const char *const EnumStrings<Aidge::ReduceMeanAttr>::data[] = { - "axes", - "keep_dims", - "noop_with_empty_axes" -}; -} #endif /* AIDGE_CORE_OPERATOR_REDUCEMEAN_H_ */ diff --git a/include/aidge/operator/ReduceSum.hpp b/include/aidge/operator/ReduceSum.hpp index 72f6bf9b2..adb58f895 100644 --- a/include/aidge/operator/ReduceSum.hpp +++ b/include/aidge/operator/ReduceSum.hpp @@ -52,6 +52,12 @@ enum class ReduceSumAttr { NoopWithEmptyAxes }; +} // namespace Aidge +namespace { + template <> + const char *const EnumStrings<Aidge::ReduceSumAttr>::data[] = {"axes", "keep_dims", "noop_with_empty_axes"}; +} +namespace Aidge { /** * @class ReduceSum_Op * @brief Implements the ReduceSum operation to compute the sum of a tensor along specified axes. @@ -100,7 +106,7 @@ public: /** * @brief constructor for ReduceSum op * @param[in] axes around which perform the operation - * @param[in] keep_dims if true we set a dimension of 1 in the place of the reduced axes and + * @param[in] keep_dims if true we set a dimension of 1 in the place of the reduced axes and * if false we remove the dimension completely * @param[in] noop_with_empty_axes used when no axes are provided, if set to true, the operator does nothing * and if false, we reduce on all axes @@ -176,7 +182,7 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::ReduceSumAttr>::data; + return EnumStrings<Aidge::ReduceSumAttr>::data; } }; @@ -202,9 +208,4 @@ inline std::shared_ptr<Node> ReduceSum(const std::vector<std::int32_t> &axes={}, } } // namespace Aidge -namespace { -template <> -const char *const EnumStrings<Aidge::ReduceSumAttr>::data[] = {"axes", "keep_dims", "noop_with_empty_axes"}; -} - #endif /* AIDGE_CORE_OPERATOR_REDUCESUM_H_ */ diff --git a/include/aidge/operator/Reshape.hpp b/include/aidge/operator/Reshape.hpp index 51623737e..e69c42d4d 100644 --- a/include/aidge/operator/Reshape.hpp +++ b/include/aidge/operator/Reshape.hpp @@ -53,21 +53,29 @@ enum class ReshapeAttr { * @brief The target shape for the output tensor. */ Shape, - + /** * @brief Whether zeros in the shape attribute are allowed. - * + * * When true, zeros in the target shape retain the corresponding dimension size from the input tensor. */ AllowZero }; - +} // namespace Aidge +namespace { + /** + * @brief EnumStrings specialization for ReshapeAttr. + */ + template <> + const char *const EnumStrings<Aidge::ReshapeAttr>::data[] = {"shape", "allow_zero"}; +} +namespace Aidge { /** * @brief Description of Reshape operator that adjusts the shape of the input tensor. * - * This operator reshapes the input tensor according to the specified target shape. - * If the target shape is not compatible with the input tensor's total number of elements, - * the operation will fail. If the `AllowZero` attribute is true, zeros in the target shape + * This operator reshapes the input tensor according to the specified target shape. + * If the target shape is not compatible with the input tensor's total number of elements, + * the operation will fail. If the `AllowZero` attribute is true, zeros in the target shape * retain the corresponding dimensions from the input tensor. * * @example Input: Tensor of dimensions `[2, 3]` with `Shape = {3, 2}` results in a tensor with dimensions `[3, 2]`. @@ -182,7 +190,7 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::ReshapeAttr>::data; + return EnumStrings<Aidge::ReshapeAttr>::data; } }; @@ -200,12 +208,5 @@ std::shared_ptr<Node> Reshape(const std::vector<std::int64_t>& shape = {}, } // namespace Aidge -namespace { -/** - * @brief EnumStrings specialization for ReshapeAttr. - */ -template <> -const char *const EnumStrings<Aidge::ReshapeAttr>::data[] = {"shape", "allow_zero"}; -} #endif /* AIDGE_CORE_OPERATOR_RESHAPE_H_ */ diff --git a/include/aidge/operator/Resize.hpp b/include/aidge/operator/Resize.hpp index 3a4ef3771..37d42fcc8 100644 --- a/include/aidge/operator/Resize.hpp +++ b/include/aidge/operator/Resize.hpp @@ -39,7 +39,17 @@ enum class ResizeAttr { InterpolationMode, PaddingMode }; - +} // namespace Aidge +namespace { + template <> + const char *const EnumStrings<Aidge::ResizeAttr>::data[] = { + "coordinate_transformation_mode", + "cubic_coeff_a", + "interpolation_mode", + "padding_mode" + }; +} +namespace Aidge { /** * @brief Resize operator, will up/downscale a given tensor given the input. * @verbatim @@ -197,7 +207,7 @@ class Resize_Op * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::ResizeAttr>::data; + return EnumStrings<Aidge::ResizeAttr>::data; } }; @@ -230,13 +240,4 @@ Resize(std::vector<float> scale = std::vector<float>(), } // namespace Aidge -namespace { -template <> -const char *const EnumStrings<Aidge::ResizeAttr>::data[] = { - "coordinate_transformation_mode", - "cubic_coeff_a", - "interpolation_mode", - "padding_mode" -}; -} #endif /* AIDGE_CORE_OPERATOR_RESIZE_H_ */ diff --git a/include/aidge/operator/Scaling.hpp b/include/aidge/operator/Scaling.hpp index c1f4514c9..fb342d345 100644 --- a/include/aidge/operator/Scaling.hpp +++ b/include/aidge/operator/Scaling.hpp @@ -23,7 +23,7 @@ #include "aidge/utils/StaticAttributes.hpp" #include "aidge/utils/Types.h" -// Caution: This operator is now deprecated and should no longer be used. +// Caution: This operator is now deprecated and should no longer be used. // It has been replaced by the MetaOperator "Quantizer" (located directly in aidge_quantization). namespace Aidge { @@ -38,7 +38,7 @@ enum class ScalingAttr { /** * @brief Number of quantization bits. * - * Specifies the bit-width used for quantization. + * Specifies the bit-width used for quantization. * For example, a value of `8` represents 8-bit quantization. */ QuantizedNbBits, @@ -51,12 +51,18 @@ enum class ScalingAttr { */ IsOutputUnsigned }; - +} // namespace Aidge +namespace { + template <> + const char* const EnumStrings<Aidge::ScalingAttr>::data[] + = {"scaling_factor", "quantized_nb_bits", "is_output_unsigned"}; +} +namespace Aidge { /** * @brief Description of a scaling operation to scale and quantize input tensors. * - * The `Scaling_Op` class applies a scaling factor to the input tensor, quantizes - * the scaled values to a specified bit-width, and outputs either signed or unsigned integers + * The `Scaling_Op` class applies a scaling factor to the input tensor, quantizes + * the scaled values to a specified bit-width, and outputs either signed or unsigned integers * based on the configuration. * * The input and output Tensors have the same dimensions. @@ -94,7 +100,7 @@ public: /** * @brief Copy-constructor. * @param[in] op Scaling_Op to copy. - * @details Copies the operator attributes and its output tensor(s), but not its input tensors. + * @details Copies the operator attributes and its output tensor(s), but not its input tensors. * The new operator has no associated input. */ Scaling_Op(const Scaling_Op& op); @@ -140,7 +146,7 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::ScalingAttr>::data; + return EnumStrings<Aidge::ScalingAttr>::data; } }; @@ -159,10 +165,5 @@ std::shared_ptr<Node> Scaling(float scalingFactor = 1.0f, const std::string& name = ""); } // namespace Aidge -namespace { -template <> -const char* const EnumStrings<Aidge::ScalingAttr>::data[] - = {"scaling_factor", "quantized_nb_bits", "is_output_unsigned"}; -} #endif /* AIDGE_CORE_OPERATOR_SCALING_H_ */ diff --git a/include/aidge/operator/Shape.hpp b/include/aidge/operator/Shape.hpp index 84d497abf..2a553fb82 100644 --- a/include/aidge/operator/Shape.hpp +++ b/include/aidge/operator/Shape.hpp @@ -62,7 +62,15 @@ enum class ShapeAttr { */ End }; - +} // namespace Aidge +namespace { + /** + * @brief EnumStrings specialization for ShapeAttr. + */ + template <> + const char *const EnumStrings<Aidge::ShapeAttr>::data[] = {"start", "end"}; +} +namespace Aidge { /** * @brief Description of the operation of extracting the shape of a tensor. * @@ -169,7 +177,7 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::ShapeAttr>::data; + return EnumStrings<Aidge::ShapeAttr>::data; } }; @@ -185,12 +193,6 @@ std::shared_ptr<Node> Shape(const std::int64_t start = 0, const std::int64_t end } // namespace Aidge -namespace { -/** - * @brief EnumStrings specialization for ShapeAttr. - */ -template <> -const char *const EnumStrings<Aidge::ShapeAttr>::data[] = {"start", "end"}; -} + #endif /* AIDGE_CORE_OPERATOR_SHAPE_H_ */ diff --git a/include/aidge/operator/Slice.hpp b/include/aidge/operator/Slice.hpp index ea4d21e9a..fa21b3d19 100644 --- a/include/aidge/operator/Slice.hpp +++ b/include/aidge/operator/Slice.hpp @@ -84,7 +84,12 @@ enum class SliceAttr { */ Steps }; - +} // namespace Aidge +namespace { + template <> + const char *const EnumStrings<Aidge::SliceAttr>::data[] = { "starts", "ends", "axes", "steps" }; +} +namespace Aidge{ /** * @class Slice_Op * @brief Implements the Slice operation for extracting sub-tensors. @@ -209,7 +214,7 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::SliceAttr>::data; + return EnumStrings<Aidge::SliceAttr>::data; } }; @@ -231,9 +236,4 @@ std::shared_ptr<Node> Slice(const std::vector<std::int64_t>& starts = {}, } // namespace Aidge -namespace { -template <> -const char *const EnumStrings<Aidge::SliceAttr>::data[] = { "starts", "ends", "axes", "steps" }; -} - #endif /* AIDGE_CORE_OPERATOR_SLICE_H_ */ diff --git a/include/aidge/operator/Softmax.hpp b/include/aidge/operator/Softmax.hpp index a7d8283a0..86e1a57e7 100644 --- a/include/aidge/operator/Softmax.hpp +++ b/include/aidge/operator/Softmax.hpp @@ -33,7 +33,15 @@ enum class SoftmaxAttr { */ Axis }; - +} // namespace Aidge +namespace { + /** + * @brief EnumStrings specialization for SoftmaxAttr. + */ + template <> + const char* const EnumStrings<Aidge::SoftmaxAttr>::data[] = {"axis"}; +} +namespace Aidge { /** * @brief Description of a Softmax operation on input Tensor along a specified axis. * @@ -136,7 +144,7 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::SoftmaxAttr>::data; + return EnumStrings<Aidge::SoftmaxAttr>::data; } }; @@ -151,12 +159,4 @@ std::shared_ptr<Node> Softmax(std::int32_t axis, const std::string& name = ""); } // namespace Aidge -namespace { -/** - * @brief EnumStrings specialization for SoftmaxAttr. - */ -template <> -const char* const EnumStrings<Aidge::SoftmaxAttr>::data[] = {"axis"}; -} - #endif /* AIDGE_CORE_OPERATOR_SOFTMAX_H_ */ diff --git a/include/aidge/operator/Split.hpp b/include/aidge/operator/Split.hpp index 9f2beb3aa..8b6acb060 100644 --- a/include/aidge/operator/Split.hpp +++ b/include/aidge/operator/Split.hpp @@ -65,7 +65,17 @@ enum class SplitAttr { */ Split }; +} // namespace Aidge +namespace { + /** + * @brief EnumStrings specialization for SplitAttr. + */ + template <> + const char* const EnumStrings<Aidge::SplitAttr>::data[] = {"axis", "split"}; + } + +namespace Aidge { /** * @class Split_Op * @brief Implements the Split operation to divide a tensor into multiple sub-tensors along a specified axis. @@ -179,7 +189,7 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::SplitAttr>::data; + return EnumStrings<Aidge::SplitAttr>::data; } }; @@ -199,12 +209,5 @@ std::shared_ptr<Node> Split(DimSize_t nbOutput, } // namespace Aidge -namespace { -/** - * @brief EnumStrings specialization for SplitAttr. - */ -template <> -const char* const EnumStrings<Aidge::SplitAttr>::data[] = {"axis", "split"}; -} #endif /* AIDGE_CORE_OPERATOR_SPLIT_H_ */ diff --git a/include/aidge/operator/Squeeze.hpp b/include/aidge/operator/Squeeze.hpp index 9a2cc8f54..69fa9d493 100644 --- a/include/aidge/operator/Squeeze.hpp +++ b/include/aidge/operator/Squeeze.hpp @@ -48,7 +48,12 @@ enum class SqueezeAttr { */ Axes }; - +} // namespace Aidge +namespace { + template <> + const char *const EnumStrings<Aidge::SqueezeAttr>::data[] = {"axes"}; +} +namespace Aidge { /** * @brief This operator has as purpose to remove dummy dimensions around given * axes. @@ -148,7 +153,7 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::SqueezeAttr>::data; + return EnumStrings<Aidge::SqueezeAttr>::data; } }; @@ -160,9 +165,4 @@ inline std::shared_ptr<Node> Squeeze(const std::vector<int8_t> axes = {}, } } // namespace Aidge -namespace { -template <> -const char *const EnumStrings<Aidge::SqueezeAttr>::data[] = {"axes"}; -} - #endif // AIDGE_CORE_OPERATOR_SQUEEZE_H_ diff --git a/include/aidge/operator/Stack.hpp b/include/aidge/operator/Stack.hpp index 0e420789d..214428447 100644 --- a/include/aidge/operator/Stack.hpp +++ b/include/aidge/operator/Stack.hpp @@ -95,7 +95,15 @@ enum class StackAttr { ForwardStep, // Tracks the current step in the forward pass. MaxElements // Maximum number of elements that can be stacked. }; - +} // namespace Aidge +namespace { + /** + * @brief String representations of the Stack operator's attributes. + */ + template <> + const char *const EnumStrings<Aidge::StackAttr>::data[] = {"forward_step", "max_elements"}; +} +namespace Aidge { /** * @class StackOp * @brief The `Stack` operator performs a stacking operation over a sequence of input tensors. @@ -218,7 +226,7 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::StackAttr>::data; + return EnumStrings<Aidge::StackAttr>::data; } }; @@ -231,12 +239,5 @@ public: std::shared_ptr<Node> Stack(std::uint32_t maxElements = 0, const std::string& name = ""); } // namespace Aidge -namespace { -/** - * @brief String representations of the Stack operator's attributes. - */ -template <> -const char *const EnumStrings<Aidge::StackAttr>::data[] = {"forward_step", "max_elements"}; -} #endif /* AIDGE_CORE_OPERATOR_STACK_H_ */ diff --git a/include/aidge/operator/Transpose.hpp b/include/aidge/operator/Transpose.hpp index d760ccd0d..2619c5ea5 100644 --- a/include/aidge/operator/Transpose.hpp +++ b/include/aidge/operator/Transpose.hpp @@ -54,13 +54,21 @@ public: enum class TransposeAttr { /** * @brief Order of the output dimensions relative to the input dimensions. - * + * * If this attribute is empty, the dimensions of the input tensor will * be reversed. */ OutputDimsOrder }; - +} // namespace Aidge +namespace { + /** + * @brief EnumStrings specialization for TransposeAttr. + */ + template <> + const char *const EnumStrings<Aidge::TransposeAttr>::data[] = {"output_dims_order"}; + } +namespace Aidge { /** * @brief Describes the operation of transposing the axes of a given tensor. * @@ -172,7 +180,7 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::TransposeAttr>::data; + return EnumStrings<Aidge::TransposeAttr>::data; } }; @@ -188,12 +196,5 @@ std::shared_ptr<Node> Transpose(const std::vector<DimSize_t> &outputDimsOrder = } // namespace Aidge -namespace { -/** - * @brief EnumStrings specialization for TransposeAttr. - */ -template <> -const char *const EnumStrings<Aidge::TransposeAttr>::data[] = {"output_dims_order"}; -} #endif /* AIDGE_CORE_OPERATOR_TRANSPOSE_H_ */ diff --git a/include/aidge/operator/Unfold.hpp b/include/aidge/operator/Unfold.hpp index bea32c6cc..d220807d6 100644 --- a/include/aidge/operator/Unfold.hpp +++ b/include/aidge/operator/Unfold.hpp @@ -71,13 +71,25 @@ enum class UnfoldAttr { */ KernelDims }; - +} // namespace Aidge +namespace { + /** + * @brief EnumStrings specialization for UnfoldAttr. + */ + template <> + const char* const EnumStrings<Aidge::UnfoldAttr>::data[] = { + "stride_dims", + "dilation_dims", + "kernel_dims" + }; +} +namespace Aidge { /** * @brief Describes the operation of unfolding a tensor into sliding blocks. - * + * * The Unfold operator extracts sliding blocks from the input tensor along * specified dimensions, controlled by stride, dilation, and kernel size. - * + * * @tparam DIM Number of dimensions involved in the operation. * * @example Input: Tensor of dimensions `[1, 3, 32, 32]`, with `KernelDims = {3, 3}`, @@ -205,7 +217,7 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::UnfoldAttr>::data; + return EnumStrings<Aidge::UnfoldAttr>::data; } }; @@ -237,16 +249,5 @@ inline std::shared_ptr<Node> Unfold( DimSize_t const (&kernelDims)[DIM], extern template class Aidge::Unfold_Op<2>; -namespace { -/** - * @brief EnumStrings specialization for UnfoldAttr. - */ -template <> -const char* const EnumStrings<Aidge::UnfoldAttr>::data[] = { - "stride_dims", - "dilation_dims", - "kernel_dims" -}; -} #endif /* AIDGE_CORE_OPERATOR_UNFOLD_H_ */ diff --git a/include/aidge/operator/Unsqueeze.hpp b/include/aidge/operator/Unsqueeze.hpp index 8c5909182..a78a98672 100644 --- a/include/aidge/operator/Unsqueeze.hpp +++ b/include/aidge/operator/Unsqueeze.hpp @@ -47,7 +47,12 @@ enum class UnsqueezeAttr { */ Axes }; - +} // namespace Aidge +namespace { + template <> + const char *const EnumStrings<Aidge::UnsqueezeAttr>::data[] = {"axes"}; +} +namespace Aidge { /** * @brief This operator has as purpose to add a dummy dimension around given * axis. Unsqueezing the 2nd dim of a tensor of dim (1,2,3,4) will result in a @@ -146,7 +151,7 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::UnsqueezeAttr>::data; + return EnumStrings<Aidge::UnsqueezeAttr>::data; } }; @@ -158,9 +163,4 @@ inline std::shared_ptr<Node> Unsqueeze(const std::vector<int8_t> &axes = {}, } } // namespace Aidge -namespace { -template <> -const char *const EnumStrings<Aidge::UnsqueezeAttr>::data[] = {"axes"}; -} - #endif // AIDGE_CORE_OPERATOR_UNSQUEEZE_H_ diff --git a/include/aidge/operator/WeightInterleaving.hpp b/include/aidge/operator/WeightInterleaving.hpp index 315bb3e2d..a8f8c3d74 100644 --- a/include/aidge/operator/WeightInterleaving.hpp +++ b/include/aidge/operator/WeightInterleaving.hpp @@ -30,10 +30,10 @@ namespace Aidge { * @brief WeightInterleaving operator Compresses the last dimension of a tensor by packing low-bitwidth values * (e.g., 2, 3, or 4 bits) into fewer bytes. * - * The operator reduces the size of the last dimension based on the bitwidth (`nb_bits`), - * packing multiple values into each byte. For example, 4-bit values result in a halved last dimension, + * The operator reduces the size of the last dimension based on the bitwidth (`nb_bits`), + * packing multiple values into each byte. For example, 4-bit values result in a halved last dimension, * while 2-bit values reduce it by a factor of 4. - * + * * The output tensor has the same shape as the input, except for the compressed last dimension. * * @see OperatorTensor @@ -78,10 +78,10 @@ public: /** * @brief Calculates the required size for the 8-bits`compactData` vector. - * + * * This function determines the minimum number of bytes needed in `compactData` * to store `dataSize` elements compacted to `nb_bits` bits each. - * + * * @param dataSize The total number of elements in the input data array. * @param nb_bits The number of bits to use for each compacted element (from 1 to 7). * @return std::size_t The required size in bytes for `compactData`. -- GitLab