| 39 | // bool getAttribute<int>(OPATTR attrName, int& obj) ; |
| 40 | |
| 41 | void compute(tensor<To> output, // N-D Tensor of data to set data to |
| 42 | tensor<Ti> input, // N-D Tensor of data to extract from |
| 43 | tensor<Tind> start, // 1-D tensor of starting indices of |
| 44 | // corresponding axis in `axes` |
| 45 | tensor<Tind> end, // 1-D tensor of ending indices (exclusive) of |
| 46 | // corresponding axis in `axes` |
| 47 | tensor<Tind> axes = NULL_TENSOR<Tind>, |
| 48 | // 1-D tensor of axes that `starts` and `ends` apply to. |
| 49 | // Negative value means counting dimensions from the back. |
| 50 | tensor<Tind> steps = NULL_TENSOR<Tind>) |
| 51 | |
| 52 | // 1-D tensor of slice step of corresponding |
| 53 | // axis in `axes`. Default to 1. |
| 54 | { |
| 55 | // Process and check the arguments |
| 56 | |
| 57 | std::stringstream errMsg; |
| 58 | |
| 59 | DIMENSION num_axes = start.shape()[0]; |
| 60 | Tind rank = output.rank(); |
| 61 | |
| 62 | if (start.rank() != 1) { |
| 63 | errMsg << "start tensor is " << start.rank() |
| 64 | << "dimensional (should be 1 dimensional)" << std::endl; |
| 65 | throw std::invalid_argument(errMsg.str().c_str()); |
| 66 | } |
| 67 | |
| 68 | if (end.rank() != 1) { |
| 69 | errMsg << "end tensor is " << end.rank() |
| 70 | << "dimensional (should be 1 dimensional)" << std::endl; |
| 71 | throw std::invalid_argument(errMsg.str().c_str()); |
| 72 | } |
| 73 | |
| 74 | if (start.shape() != end.shape()) { |
| 75 | errMsg << "start and end tensor sizes don't match ("; |
| 76 | errMsg << "start tensor size = " << start.shape()[0] << ", "; |
| 77 | errMsg << "end tensor size = " << end.shape()[0] << std::endl; |
| 78 | throw std::invalid_argument(errMsg.str().c_str()); |
| 79 | } |
| 80 | |
| 81 | if (axes == NULL_TENSOR<int>) { |
| 82 | std::vector<DIMENSION> shape{num_axes}; |
| 83 | tensor<int> default_axis(shape); |
| 84 | axes = default_axis; |
| 85 | for (size_t i = 0; i < num_axes; i++) { |
| 86 | axes(i) = i; |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | if (steps == NULL_TENSOR<DIMENSION>) { |
| 91 | std::vector<DIMENSION> shape{num_axes}; |
| 92 | tensor<Tind> default_steps(shape); |
| 93 | steps = default_steps; |
| 94 | for (size_t i = 0; i < num_axes; i++) { |
| 95 | steps(i) = 1; |
| 96 | } |
| 97 | } |
| 98 | |