| 68 | |
| 69 | |
| 70 | void Reduce(const TensorInfo& inputInfo, |
| 71 | const TensorInfo& outputInfo, |
| 72 | Decoder<float>& input, |
| 73 | Encoder<float>& output, |
| 74 | const std::vector<uint32_t> axis, |
| 75 | const ReduceOperation reduceOperation) |
| 76 | { |
| 77 | armnn::TensorShape inputDims = inputInfo.GetShape(); |
| 78 | unsigned int inputNumDims = inputInfo.GetNumDimensions(); |
| 79 | unsigned int numOutputs = outputInfo.GetNumElements(); |
| 80 | |
| 81 | // Initialise temp output |
| 82 | std::vector<float> tempOut(numOutputs); |
| 83 | switch(reduceOperation) |
| 84 | { |
| 85 | case ReduceOperation::Mean: |
| 86 | case ReduceOperation::Sum: |
| 87 | std::fill(tempOut.begin(), tempOut.end(), 0.0f); |
| 88 | break; |
| 89 | case ReduceOperation::Prod: |
| 90 | std::fill(tempOut.begin(), tempOut.end(), 1.0f); |
| 91 | break; |
| 92 | case ReduceOperation::Max: |
| 93 | std::fill(tempOut.begin(), tempOut.end(), -1 * std::numeric_limits<float>::max()); |
| 94 | break; |
| 95 | case ReduceOperation::Min: |
| 96 | std::fill(tempOut.begin(), tempOut.end(), std::numeric_limits<float>::max()); |
| 97 | break; |
| 98 | default: |
| 99 | throw armnn::InvalidArgumentException("Unknown reduce method: " + |
| 100 | std::to_string(static_cast<int>(reduceOperation))); |
| 101 | } |
| 102 | |
| 103 | // Initialise temp index |
| 104 | std::vector<unsigned int> tempIndex(inputNumDims, 0); |
| 105 | |
| 106 | std::vector<unsigned int> resolvedAxis = axis; |
| 107 | if (resolvedAxis.empty()) |
| 108 | { |
| 109 | for (unsigned int idx = 0; idx < inputNumDims; ++idx) |
| 110 | { |
| 111 | resolvedAxis.push_back(idx); |
| 112 | } |
| 113 | } |
| 114 | auto numResolvedAxis = armnn::numeric_cast<unsigned int>(resolvedAxis.size()); |
| 115 | |
| 116 | // Iterates through input_data and operates over the reduced axis |
| 117 | for (bool hasNext = true; hasNext; hasNext = NextIndex(inputNumDims, inputDims, tempIndex)) |
| 118 | { |
| 119 | unsigned int inputOffset = ReducedOutputOffset(inputNumDims, inputDims, tempIndex, 0, {}); |
| 120 | unsigned int outputOffset = ReducedOutputOffset(inputNumDims, inputDims, tempIndex, |
| 121 | numResolvedAxis, resolvedAxis); |
| 122 | input[inputOffset]; |
| 123 | auto inputValue = input.Get(); |
| 124 | switch(reduceOperation) |
| 125 | { |
| 126 | case ReduceOperation::Mean: |
| 127 | case ReduceOperation::Sum: |
no test coverage detected