From 48184df31b7f39ccab0a0be129033bc466f6c599 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20KUBLER?= <gregoire.kubler@proton.me> Date: Tue, 17 Dec 2024 17:46:28 +0100 Subject: [PATCH] fix : [Conv] added check to ensure that dilation & stride values were all >= 1 Also better warning message for conv operator constructor --- include/aidge/operator/Conv.hpp | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/include/aidge/operator/Conv.hpp b/include/aidge/operator/Conv.hpp index 8984ebd08..ac273a64b 100644 --- a/include/aidge/operator/Conv.hpp +++ b/include/aidge/operator/Conv.hpp @@ -12,6 +12,7 @@ #ifndef AIDGE_CORE_OPERATOR_CONV_H_ #define AIDGE_CORE_OPERATOR_CONV_H_ +#include <algorithm> #include <array> #include <cmath> // std::floor #include <cstddef> // std::size_t @@ -237,10 +238,16 @@ std::shared_ptr<Node> Conv(DimSize_t inChannels, bool noBias = false); /** - * @brief Helper function for Conv with C-style arrays. + * @brief Perform a convolution on the input Tensor. * - * This helper function allows automatic template deduction of the number of dimensions (DIM) - * based on the kernel dimensions provided. + * @tparam DIM Number of dimensions for the feature map. + * @param inChannels Number of input channels. + * @param outChannels Number of output channels. + * @param kernelDims Dimensions of the kernel. Must be the same number of dimensions as the feature map. + * @param name Name of the operator. + * @param strideDims Dimensions of the stride attribute. Must be the same number of dimensions as the feature map. + * @param dilationDims Dimensions of the dilation attribute. Must be the same number of dimensions as the feature map. + * @return std::shared_ptr<Node> A Node containing the operator. */ template <DimSize_t DIM> inline std::shared_ptr<Node> Conv( @@ -251,8 +258,22 @@ inline std::shared_ptr<Node> Conv( const std::array<DimSize_t, DIM> &strideDims = create_array<DimSize_t,DIM>(1), const std::array<DimSize_t, DIM> &dilationDims = create_array<DimSize_t,DIM>(1), bool noBias = false) { - static_assert(DIM<=MaxDim,"Too many kernel dimensions required by Conv, not supported"); - return Conv(inChannels, outChannels, to_array(kernelDims), name, strideDims, dilationDims, noBias); + AIDGE_ASSERT(DIM<=MaxDim,"{}: Too many kernel dimensions required, maximum allowed : {} ", Conv_Op<DIM>::Type, MaxDim); + AIDGE_ASSERT(!std::any_of(dilationDims.cbegin(), + dilationDims.cend(), + [](DimSize_t val) { return val == 0; }), + "Conv : at least of of the dilation dimension is 0, expecting " + "strictly positive values. Got {}", + Conv_Op<DIM>::Type, + dilationDims); + AIDGE_ASSERT(!std::any_of(strideDims.cbegin(), + strideDims.cend(), + [](DimSize_t val) { return val == 0; }), + "{}: at least one of the stride dimension is 0, expecting " + "strictly positive values. Got {}.", + Conv_Op<DIM>::Type, + strideDims); + return Conv<DIM>(inChannels, outChannels, to_array(kernelDims), name, strideDims, dilationDims, noBias); } } // namespace Aidge -- GitLab