// // Copyright © 2017 Arm Ltd. All rights reserved. // SPDX-License-Identifier: MIT // #include "ArgMinMaxLayer.hpp" #include "LayerCloneBase.hpp" #include #include #include #include namespace armnn { ArgMinMaxLayer::ArgMinMaxLayer(const ArgMinMaxDescriptor& param, const char* name) : LayerWithParameters(1, 1, LayerType::ArgMinMax, param, name) { } std::unique_ptr ArgMinMaxLayer::CreateWorkload(const IWorkloadFactory& factory) const { ArgMinMaxQueueDescriptor descriptor; return factory.CreateArgMinMax(descriptor, PrepInfoAndDesc(descriptor)); } ArgMinMaxLayer* ArgMinMaxLayer::Clone(Graph& graph) const { return CloneBase(graph, m_Param, GetName()); } std::vector ArgMinMaxLayer::InferOutputShapes(const std::vector& inputShapes) const { ARMNN_ASSERT(inputShapes.size() == 1); TensorShape inputShape = inputShapes[0]; auto inputNumDimensions = inputShape.GetNumDimensions(); auto axis = m_Param.m_Axis; auto unsignedAxis = armnnUtils::GetUnsignedAxis(inputNumDimensions, axis); ARMNN_ASSERT(unsignedAxis <= inputNumDimensions); // 1D input shape results in scalar output if (inputShape.GetNumDimensions() == 1) { std::vector tensorDimensions(1, 1); TensorShape outputShape(1, tensorDimensions.data()); return std::vector({ outputShape }); } std::vector tensorDimensions(inputNumDimensions - 1, 0); for (unsigned int i = 0; i < unsignedAxis; ++i) { tensorDimensions[i] = inputShape[i]; } for (unsigned int i = unsignedAxis + 1; i < inputNumDimensions; ++i) { tensorDimensions[i - 1] = inputShape[i]; } TensorShape outputShape = TensorShape(inputNumDimensions - 1, tensorDimensions.data()); return std::vector({ outputShape }); } void ArgMinMaxLayer::ValidateTensorShapesFromInputs(ShapeInferenceMethod shapeInferenceMethod) { IgnoreUnused(shapeInferenceMethod); VerifyLayerConnections(1, CHECK_LOCATION()); auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetConnection()->GetTensorInfo().GetShape() }); ARMNN_ASSERT(inferredShapes.size() == 1); ConditionalThrowIfNotEqual( "ArgMinMaxLayer: TensorShape set on OutputSlot does not match the inferred shape.", GetOutputSlot(0).GetTensorInfo().GetShape(), inferredShapes[0]); } void ArgMinMaxLayer::Accept(ILayerVisitor& visitor) const { visitor.VisitArgMinMaxLayer(this, GetParameters(), GetName()); } } // namespace armnn