From 7c75e336fbeeec052a1cb90c68d1caece332c176 Mon Sep 17 00:00:00 2001 From: Declan-ARM Date: Tue, 12 Mar 2024 16:40:25 +0000 Subject: IVGCVSW-7853 Assert audit and removal * src/armnn * src/armnn/layers Signed-off-by: Declan-ARM Change-Id: Ic78cbbb59e90fbb15f893205a358c45264243721 --- src/armnn/layers/MeanLayer.cpp | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'src/armnn/layers/MeanLayer.cpp') diff --git a/src/armnn/layers/MeanLayer.cpp b/src/armnn/layers/MeanLayer.cpp index bd49f509a0..62a3923750 100644 --- a/src/armnn/layers/MeanLayer.cpp +++ b/src/armnn/layers/MeanLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -52,19 +52,35 @@ void MeanLayer::ValidateTensorShapesFromInputs() std::vector inferredShapes = InferOutputShapes( { GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); - ARMNN_ASSERT(inferredShapes[0].GetDimensionality() == Dimensionality::Specified); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } + + if (inferredShapes[0].GetDimensionality() != Dimensionality::Specified) + { + throw armnn::LayerValidationException("inferredShapes' dimensionality has not been specified."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "MeanLayer"); } std::vector MeanLayer::InferOutputShapes(const std::vector& inputShapes) const { - ARMNN_ASSERT(inputShapes.size() == 1); + if (inputShapes.size() != 1) + { + throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"1\"."); + } + const TensorShape& input = inputShapes[0]; - ARMNN_ASSERT_MSG(input.GetNumDimensions() > 0 && input.GetNumDimensions() <= 4, - "MeanLayer: Mean supports up to 4D input."); + if (auto inputDims = input.GetNumDimensions(); inputDims != std::clamp(inputDims, 1u, 4u)) + { + throw armnn::Exception("ReduceLayer: Reduce supports up to 4D input."); + } unsigned int rank = input.GetNumDimensions(); unsigned int outputRank = 0; -- cgit v1.2.1