diff --git a/include/aidge/operator/ArgMax.hpp b/include/aidge/operator/ArgMax.hpp index 6d24d87bdb7e9e1d86896add0f1c1373cad01fbf..bc97e1f5bdd4dcc80857db55b66e9b6bedb1fa62 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 7e02a94ab486753cd418ee0b697ce90d1f2299af..e73387ce1daf7b08d087faecf5a30edaffc6d54d 100644 --- a/include/aidge/operator/AvgPooling.hpp +++ b/include/aidge/operator/AvgPooling.hpp @@ -49,13 +49,23 @@ enum class AvgPoolingAttr { */ CeilMode }; - +} // namespace Aidge +namespace { + /** + * @brief String representation of the AvgPooling attributes. + */ + template <> + const char *const EnumStrings<Aidge::AvgPoolingAttr>::data[] = { + "stride_dims", "kernel_dims", "dilations", "ceil_mode" + }; +} +namespace Aidge { /** * @brief Class representing an Average Pooling operation. * * The AvgPooling operation computes the average value within sliding windows of specified size * (kernel dimensions) over the input tensor. The stride dimensions determine how the window - * moves across the input. The dilation parameter allows spacing between kernel elements, and + * moves across the input. The dilation parameter allows spacing between kernel elements, and * `ceil_mode` determines whether to use ceiling instead of floor when computing the output shape. * This operation is commonly used in neural networks to reduce spatial dimensions while preserving features. * @@ -229,7 +239,7 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::AvgPoolingAttr>::data; + return EnumStrings<Aidge::AvgPoolingAttr>::data; } }; @@ -280,12 +290,5 @@ 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", "dilations", "ceil_mode" }; -} #endif /* AIDGE_CORE_OPERATOR_AVGPOOLING_H_ */ diff --git a/include/aidge/operator/BatchNorm.hpp b/include/aidge/operator/BatchNorm.hpp index 995179d7fc5bd58254d60e90f259298e1c4ec5d4..3521c9b16dcbbf73b0c3c4aea9d93047dc0a2f61 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 d066507dda0fe37de21510f5f1858b7b3f497bdb..3e9f8c3f22728afc4fae7abf5f60adc13c89ac76 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 12c3a280a7632f1570e1f72c8d61c1e8044801af..b2ffbb553ce44f66f371a65f35340193bf04dab4 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 93c042d8670a0294e252addb56e45a71af7a22a9..51ecb6eb36591c2e22ea47ba529b87d125c92a65 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 7a4ea74a43ada9112096bec35b5c3f7a8edf2c74..1f8a357a830ef3bf3d945ea488425128ea99d3ed 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 d837d108af908ad1a36aca5feab3c097dda27a24..6176f69dd9e2595793ab787eb1fb2fba3765d085 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 7beea057eceeec5f7385792a82b1344813fd6a62..135ff8860706d245ae6095322d6cf017456cc2e1 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 3090b9febf8a37f54e09738d3a6737c818587d08..b307d67a61cabd416bb96db8558fb6960cd65cc4 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 cc51ea180fe8998ae667d691a73ff408a5053933..c99f7bbb7d882300b7f2f4278dda832189064ad5 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 10ce58ad046d15b31eed192c931e4ba4b1e1825a..b61fc6912dd0e9f61dd2506370c591aae8c3a107 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 9d2d4e0df7560c19f391117654f9fffcc40a79e1..2f9974e8ed3b1723734a2483616feceace5bec33 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 3842a041edf235ca902094914e464d9682c02cd9..86fc7bc7855473c6f73e3bcc36d46ef9b4956446 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 28c5fb5e520c7d55ff6d5b78b268d8a8a1f30c2b..06642231152cefe1023688811da0dcdc0bbde859 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 874853c4ebe0a4db9551e95b814a55ae7637d227..806ed47f3db5f78b5636f7f14876f852ea22b341 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 9019c089be7d062cf2bf28a8afc2f667a1014b34..6c82b6b4670cff44e9d21aeabe8f64aa2b2e2397 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 5381b3cb1d8df445970e354a09bfad628d2773ad..acf9bae7f4955fee09699f27b7a23c06ce3d670e 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 f4f38de4a391a3f0815f256f19089455bbe721e6..d90aab4a0b7581a5d1e2c7eaf6fb295e51953af4 100644 --- a/include/aidge/operator/MaxPooling.hpp +++ b/include/aidge/operator/MaxPooling.hpp @@ -59,6 +59,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", "dilations", "ceil_mode"}; + } + +namespace Aidge{ /** * @class MaxPooling_Op @@ -66,8 +76,8 @@ enum class MaxPoolingAttr { * @brief Implements the MaxPooling operation over a specified input tensor. * * MaxPooling reduces spatial dimensions by applying a max filter over a sliding window. - * The stride dimensions determine how the window moves across the input. The dilation - * parameter allows spacing between kernel elements, and `ceil_mode` determines whether + * The stride dimensions determine how the window moves across the input. The dilation + * parameter allows spacing between kernel elements, and `ceil_mode` determines whether * to use ceiling instead of floor when computing the output shape. * * ### Output Shape Calculation @@ -204,7 +214,7 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::MaxPoolingAttr>::data; + return EnumStrings<Aidge::MaxPoolingAttr>::data; } }; @@ -255,12 +265,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", "dilations", "ceil_mode"}; -} #endif /* AIDGE_CORE_OPERATOR_MAXPOOLING_H_ */ diff --git a/include/aidge/operator/Memorize.hpp b/include/aidge/operator/Memorize.hpp index 10bbfce8505221ce40c6a33c367ad4bb639e29fb..59df17ec146bb33dc1e6e8c007eb275054fd727b 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 417e9664c1d414fe6896ea2a73c78f478871ff46..de7c3d2b21b1c2770218a1892aacbb807c2d44e7 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 630c58c0d2931bd394d0bca12395328199105ffc..d9d52f9bcd07a671d68e3db53c378c9ee6659c8e 100644 --- a/include/aidge/operator/Pop.hpp +++ b/include/aidge/operator/Pop.hpp @@ -101,7 +101,17 @@ enum class PopAttr { ForwardStep, // Tracks the current step in the forward pass BackwardStep // Tracks the current step in the backward pass }; - +} // namespace Aidge +namespace { + /** + * @brief String representations of the `Pop` operator's attributes. + */ + template <> + const char *const EnumStrings<Aidge::PopAttr>::data[] = { + "forward_step", "backward_step" + }; +} +namespace Aidge { /** * @class Pop_Op * @brief The `Pop` operator is responsible for removing and outputting elements from a data structure. @@ -217,7 +227,7 @@ public: * @return A vector containing the attributes name. */ static const char* const* attributesName(){ - return EnumStrings<Aidge::PopAttr>::data; + return EnumStrings<Aidge::PopAttr>::data; } }; @@ -229,14 +239,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", "backward_step" -}; -} #endif /* AIDGE_CORE_OPERATOR_POP_H_ */ diff --git a/include/aidge/operator/Producer.hpp b/include/aidge/operator/Producer.hpp index 1d6b965820e90dcd9b54c61795358c5332d77efc..3690579d34373b64eec20042b7f9615266c15aee 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 c6d8757196298134affa3896942a6277cc5811c8..3ee4a1bec40f7f6aa409308708bc3338174c652b 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 72f6bf9b2fd68c3f7073f049164e1c7c99db7d61..adb58f895cf3fbfa67b84c518a7f6cedf09d1a19 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 51623737e4af616fcc34de0af94d60a2549c1cdb..e69c42d4d98974e7bb00acbf17581cd56ada1331 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 3a4ef37711aaeeb86cd9a13a678d0603e4cc4596..37d42fcc861db42c991a6e7f4296d725d002aad5 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 c1f4514c9aa807247684bb0a4ff834b42b50e4d3..fb342d34580092febaf3d1e63ea78247c3e8f77a 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 84d497abf72c1ae04be95d6ad2c160b08c3acd01..2a553fb827fc8a8d4b03fa06ebcd8825ae2ed64f 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 ea4d21e9a513ad16e2aeb1aacbb5767ced299bd1..fa21b3d197551e54a95fe29dbb8e3f83d30865af 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 a7d8283a0bd69fb41c49337efe6f52bd8953a50b..86e1a57e70c4b7070b9af279980b2d5344a2f6f0 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 9f2beb3aa87c4e4074b9c69f71edb58b55684911..8b6acb06023f5f71cbb71b42281f21bda19caaed 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 9a2cc8f54fc4676a15a9298208c45a2620c86edb..69fa9d493a321199ea2fddd61c7b769a668c6f42 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 0e420789daeb02d1ca0015f21697b2f345e5db3f..21442844789f065cf0f127db4380f70c4618ca86 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 d760ccd0d6395e86bbd6c95694455beeaffff464..2619c5ea5d41407100b66f909d6f64176027f74c 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 bea32c6cc48b9eac6c90993ca059362c8d10ab8b..d220807d6cd4ea2c57c152c9e8351bc48211d06e 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 8c590918264a63b2e7fb98196e83c1b1fb4f91f5..a78a986724d4b5ca06f611b82e057d13183c5015 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 315bb3e2dd163f23949ac09719a20c335e03c265..a8f8c3d743aaef11bea0bbc03c949907348a7d7c 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`.