| 105 | // applicable special case and wrote to the outputs. Otherwise acts as a no-op. |
| 106 | template <typename T> |
| 107 | Status SplitEasyCases(OpKernelContext* context, const Tensor& input, |
| 108 | const gtl::ArraySlice<int64>& sizes, |
| 109 | std::vector<Tensor>* outputs, bool* done) { |
| 110 | *done = false; |
| 111 | |
| 112 | int64 total_size = 0; |
| 113 | for (const int64 size : sizes) { |
| 114 | total_size += size; |
| 115 | } |
| 116 | if (total_size > input.shape().dim_size(0)) { |
| 117 | return errors::InvalidArgument( |
| 118 | "Sum of split sizes must not exceed dim0-size of input tensor"); |
| 119 | } |
| 120 | |
| 121 | // Special case 0: trivial 1-way split. |
| 122 | if (sizes.size() == 1 && sizes.at(0) == input.shape().dim_size(0)) { |
| 123 | outputs->push_back(input); |
| 124 | *done = true; |
| 125 | return Status::OK(); |
| 126 | } |
| 127 | |
| 128 | // Special case 1: input is aligned. |
| 129 | if (IsInnerDimsSizeAligned<T>(input.shape())) { |
| 130 | int64 position = 0; |
| 131 | for (const int64 size : sizes) { |
| 132 | outputs->emplace_back(input.Slice(position, position + size)); |
| 133 | position += size; |
| 134 | } |
| 135 | *done = true; |
| 136 | return Status::OK(); |
| 137 | } |
| 138 | |
| 139 | return Status::OK(); |
| 140 | } |
| 141 | |
| 142 | // Handles the general case, on CPU. |
| 143 | template <typename T> |
nothing calls this directly
no test coverage detected