16 const void* inputData,
18 unsigned int dataTypeSize)
23 constexpr
unsigned int maxNumDims = 4;
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(4);
47 std::vector<unsigned int> paddedBegin(4);
48 std::vector<unsigned int> paddedSize (4);
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];
73 unsigned int begin0 = paddedBegin[0];
74 unsigned int begin1 = paddedBegin[1];
75 unsigned int begin2 = paddedBegin[2];
76 unsigned int begin3 = paddedBegin[3];
78 unsigned int size0 = paddedSize[0];
79 unsigned int size1 = paddedSize[1];
80 unsigned int size2 = paddedSize[2];
81 unsigned int size3 = paddedSize[3];
83 if (begin0 + size0 > dim0)
85 std::stringstream msg;
86 msg <<
"Slice: begin0 + size0 (" << (begin0 + size0) <<
87 ") exceeds dim0 (" << dim0 <<
")";
90 if (begin1 + size1 > dim1)
92 std::stringstream msg;
93 msg <<
"Slice: begin1 + size1 (" << (begin1 + size1) <<
94 ") exceeds dim2 (" << dim1 <<
")";
97 if (begin2 + size2 > dim2)
99 std::stringstream msg;
100 msg <<
"Slice: begin2 + size2 (" << (begin2 + size2) <<
101 ") exceeds dim2 (" << dim2 <<
")";
104 if (begin3 + size3 > dim3)
106 std::stringstream msg;
107 msg <<
"Slice: begin3 + size3 (" << (begin3 + size3) <<
108 ") exceeds dim3 (" << dim3 <<
")";
112 if (inputData ==
nullptr)
116 if (outputData ==
nullptr)
121 const unsigned char* input =
reinterpret_cast<const unsigned char*
>(inputData);
122 unsigned char* output =
reinterpret_cast<unsigned char*
>(outputData);
124 for (
unsigned int idx0 = begin0; idx0 < begin0 + size0; ++idx0)
126 for (
unsigned int idx1 = begin1; idx1 < begin1 + size1; ++idx1)
128 for (
unsigned int idx2 = begin2; idx2 < begin2 + size2; ++idx2)
130 for (
unsigned int idx3 = begin3; idx3 < begin3 + size3; ++idx3)
132 const unsigned int inputOffset =
133 (((idx0 * dim1 + idx1) * dim2 + idx2) * dim3 + idx3) * dataTypeSize;
135 ::memcpy(output, input + inputOffset, dataTypeSize);
136 output += dataTypeSize;