MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / SplitEasyCases

Function SplitEasyCases

tensorflow/core/kernels/batch_kernels.cc:107–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

105// applicable special case and wrote to the outputs. Otherwise acts as a no-op.
106template <typename T>
107Status 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.
143template <typename T>

Callers

nothing calls this directly

Calls 8

InvalidArgumentFunction · 0.85
dim_sizeMethod · 0.45
shapeMethod · 0.45
sizeMethod · 0.45
atMethod · 0.45
push_backMethod · 0.45
emplace_backMethod · 0.45
SliceMethod · 0.45

Tested by

no test coverage detected