Skip to content

[Parameter] Cannot get the first attribute of an object

Context

When developping recipies I tried to get the Epsilon parameter of the BatchNormOp

float epsilon = std::static_pointer_cast<BatchNorm_Op<2>>(batchnorm->getOperator())->get("Epsilon");

However I get:

/XXXX/aidge/aidge/aidge_core/include/aidge/utils/Parameter.hpp:159: constexpr typename std::enable_if<(SIZE <= 0), R&>::type Aidge::Parameterizable<PARAM_ENUM, T>::get(std::size_t) [with R = float; long unsigned int SIZE = 0; PARAM_ENUM = Aidge::BatchNormParam; T = {float, float}; typename std::enable_if<(SIZE <= 0), R&>::type = float&; std::size_t = long unsigned int]: Assertion `false && "parameter not found"' failed.

Bug

Looks like we are recursively looking for the parameter index and we have the exit condiiton wirtten here: https://gitlab.eclipse.org/eclipse/aidge/aidge_core/-/blob/main/include/aidge/utils/Parameter.hpp?ref_type=heads#L158

However the stop condition is : (SIZE <= 0) and the idx of the first attribute is ... 0 !

Meaning that when trying to get the first attribute we always go into this function and raise parameter not found error.

Proposed fix

We need to change the check from (SIZE <= 0) to (SIZE == std::numeric_limits<std::size_t>::max())