16 const void* inputData,
18 unsigned int dataTypeSize)
23 constexpr
unsigned int maxNumDims = 5;
24 if (descriptor.
m_Begin.size() != numDims)
26 std::stringstream msg;
27 msg <<
"Slice: Number of dimensions (" << numDims <<
28 ") does not match the Begin vector in the descriptor (" << descriptor.
m_Begin.size() <<
")";
31 if (descriptor.
m_Size.size() != numDims)
33 std::stringstream msg;
34 msg <<
"Slice: Number of dimensions (" << numDims <<
35 ") does not match the Size vector in the descriptor (" << descriptor.
m_Size.size() <<
")";
38 if (numDims > maxNumDims)
40 std::stringstream msg;
41 msg <<
"Slice: Number of dimensions (" << numDims <<
42 ") is greater than the maximum supported (" << maxNumDims <<
")";
46 std::vector<unsigned int> paddedInput(5);
47 std::vector<unsigned int> paddedBegin(5);
48 std::vector<unsigned int> paddedSize (5);
50 const unsigned int numPaddingDims = maxNumDims - numDims;
51 for (
unsigned int i = 0u; i < maxNumDims; ++i)
53 if (i < numPaddingDims)
61 const unsigned int j = i - numPaddingDims;
62 paddedInput[i] = inputShape[j];
63 paddedBegin[i] = descriptor.
m_Begin[j];
64 paddedSize[i] = descriptor.
m_Size[j];
68 unsigned int dim0 = paddedInput[0];
69 unsigned int dim1 = paddedInput[1];
70 unsigned int dim2 = paddedInput[2];
71 unsigned int dim3 = paddedInput[3];
72 unsigned int dim4 = paddedInput[4];
74 unsigned int begin0 = paddedBegin[0];
75 unsigned int begin1 = paddedBegin[1];
76 unsigned int begin2 = paddedBegin[2];
77 unsigned int begin3 = paddedBegin[3];
78 unsigned int begin4 = paddedBegin[4];
80 unsigned int size0 = paddedSize[0];
81 unsigned int size1 = paddedSize[1];
82 unsigned int size2 = paddedSize[2];
83 unsigned int size3 = paddedSize[3];
84 unsigned int size4 = paddedSize[4];
86 if (begin0 + size0 > dim0)
88 std::stringstream msg;
89 msg <<
"Slice: begin0 + size0 (" << (begin0 + size0) <<
90 ") exceeds dim0 (" << dim0 <<
")";
93 if (begin1 + size1 > dim1)
95 std::stringstream msg;
96 msg <<
"Slice: begin1 + size1 (" << (begin1 + size1) <<
97 ") exceeds dim2 (" << dim1 <<
")";
100 if (begin2 + size2 > dim2)
102 std::stringstream msg;
103 msg <<
"Slice: begin2 + size2 (" << (begin2 + size2) <<
104 ") exceeds dim2 (" << dim2 <<
")";
107 if (begin3 + size3 > dim3)
109 std::stringstream msg;
110 msg <<
"Slice: begin3 + size3 (" << (begin3 + size3) <<
111 ") exceeds dim3 (" << dim3 <<
")";
115 if (inputData ==
nullptr)
119 if (outputData ==
nullptr)
124 const unsigned char* input =
reinterpret_cast<const unsigned char*
>(inputData);
125 unsigned char* output =
reinterpret_cast<unsigned char*
>(outputData);
127 for (
unsigned int idx0 = begin0; idx0 < begin0 + size0; ++idx0)
129 for (
unsigned int idx1 = begin1; idx1 < begin1 + size1; ++idx1)
131 for (
unsigned int idx2 = begin2; idx2 < begin2 + size2; ++idx2)
133 for (
unsigned int idx3 = begin3; idx3 < begin3 + size3; ++idx3)
135 for (
unsigned int idx4 = begin4; idx4 < begin4 + size4; ++idx4)
137 const unsigned int inputOffset =
138 ((((idx0 * dim1 + idx1) * dim2 + idx2) * dim3 + idx3) * dim4 + idx4) * dataTypeSize;
140 ::memcpy(output, input + inputOffset, dataTypeSize);
141 output += dataTypeSize;