Skip to content

[core] Operator Attributes consistency

Context

Currently, there is a triple definition for Operator attributes that MUST be kept in synch:

1. enum definition

enum class MaxPoolingAttr {
  StrideDims,
  Dilations,
  KernelDims,
  CeilMode,
};

2. name definition

namespace {
    template <>
    const char *const EnumStrings<Aidge::MaxPoolingAttr>::data[] = {"stride_dims", "kernel_dims", "dilations", "ceil_mode"};
}

3. StaticAttribute declaration

    using Attributes_ = StaticAttributes<MaxPoolingAttr,
                                         std::array<DimSize_t, DIM>,
                                         std::array<DimSize_t, DIM>,
                                         std::array<DimSize_t, DIM>,
                                         bool>;

This is quite error prone (see !346 (merged))

Options to solve this

1. Create a unit-test

Create a unit-test for each Operator that would test:

  • the size of the enum is the same as EnumStrings::data[]. (how to check Attributes_?)
  • the correspondance between enum and names (again, how?)

2. Guarantee synchronization at construction

Use X-macros to keep multiple lists in synch

// Define the X‑macro list with three parameters: name, string, and type.
#define LIST_MAXPOOLING_ATTR(X)                                \
    X(KernelDims, "kernel_dims", std::array<DimSize_t, DIM>)   \
    X(StrideDims, "stride_dims", std::array<DimSize_t, DIM>)   \
    X(Dilations,  "dilations",  std::array<DimSize_t, DIM>)    \
    X(CeilMode,   "ceil_mode",  bool)
Edited by Maxence Naud