Content in this function (fixes related to NewAxisMask and EllipsisMask) are paraphrased from: tensorflow/tensorflow/lite/kernels/strided_slice.cc from the function BuildStridedSliceParams
| 50 | // Content in this function (fixes related to NewAxisMask and EllipsisMask) are paraphrased from: |
| 51 | // tensorflow/tensorflow/lite/kernels/strided_slice.cc from the function BuildStridedSliceParams |
| 52 | std::vector<TensorShape> StridedSliceLayer::InferOutputShapes( |
| 53 | const std::vector<TensorShape>& inputShapes) const |
| 54 | { |
| 55 | if (inputShapes.size() != 1) |
| 56 | { |
| 57 | throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) + |
| 58 | "\" - should be \"1\"."); |
| 59 | } |
| 60 | |
| 61 | TensorShape inputShape = inputShapes[0]; |
| 62 | std::vector<unsigned int> outputShape; |
| 63 | unsigned int amountDimShrunk{0}; |
| 64 | |
| 65 | // Getting the actual number of output dimensions, including axes added with the NewAxisMask |
| 66 | unsigned int outputDims = inputShape.GetNumDimensions(); |
| 67 | for(unsigned int i = 0; i < m_Param.m_Begin.size(); ++i) |
| 68 | { |
| 69 | // Adding to dimension count for every set bit of NewAxisMask not covered by the EllipsisMask |
| 70 | if(m_Param.m_NewAxisMask & (1 << i) && !(m_Param.m_EllipsisMask & (1 << i))) |
| 71 | { |
| 72 | ++outputDims; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | // Modifying the EllipsisMask based on the NewAxisMask (expand for any newly added axes) |
| 77 | // and the NewAxisMask based on the EllipsisMask (offset based on the expanded ellipsis) |
| 78 | int realEllipsisMask = 0, realNewAxisMask = 0; |
| 79 | // The number of bits the ellipsis mask was expanded by |
| 80 | unsigned int ellipsisExpandedBy = 0; |
| 81 | for(unsigned int i = 0; i < outputDims; ++i) |
| 82 | { |
| 83 | if(m_Param.m_EllipsisMask & (1 << i)) |
| 84 | { |
| 85 | // The end index of the expanded ellipsis mask (start is at i) |
| 86 | // End Index calculation - i+1 (for non-expanded ellipsis) + outputDims-inputDims (number of added dims) |
| 87 | unsigned int endIdx = std::min(i + 1u + outputDims - inputShape.GetNumDimensions(), outputDims); |
| 88 | |
| 89 | // Calculation: the total size of the mask -1 for the already existing bit in the original mask |
| 90 | ellipsisExpandedBy = endIdx - i - 1; |
| 91 | |
| 92 | // Setting mask bit to 1 for the entire expanded ellipsis |
| 93 | for(; i < endIdx; ++i) |
| 94 | { |
| 95 | realEllipsisMask |= (1 << i); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | // Setting the real NewAxisMask based on the expanded ellipsis size |
| 100 | if(m_Param.m_NewAxisMask & (1 << (i - ellipsisExpandedBy))) |
| 101 | { |
| 102 | realNewAxisMask |= (1 << i); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | // The backwards offset by which i is ahead of the actual inputTensor dimension |
| 107 | unsigned int inputDimOffset = 0; |
| 108 | // Iterating through the parameters and inferring output shape |
| 109 | for (unsigned int i = 0; i < outputDims; ++i) |
nothing calls this directly
no test coverage detected