@@ -261,82 +261,5 @@ bool check_select_scatter_args(
261
261
return true ;
262
262
}
263
263
264
- bool check_slice_scatter_args (
265
- const Tensor& input,
266
- const Tensor& src,
267
- int64_t dim,
268
- int64_t num_values,
269
- int64_t step,
270
- Tensor output) {
271
- ET_LOG_AND_RETURN_IF_FALSE (input.dim () > 0 );
272
-
273
- // Check dim. The dim planed to be selected on shall exist in input
274
- ET_LOG_AND_RETURN_IF_FALSE (dim_is_valid (dim, input.dim ()));
275
-
276
- // Input and output tensors should be the same shape and dtype
277
- ET_LOG_AND_RETURN_IF_FALSE (tensors_have_same_shape_and_dtype (input, output));
278
-
279
- // The input.dim() shall equal to src.dim()
280
- ET_LOG_AND_RETURN_IF_FALSE (tensors_have_same_rank (input, src));
281
-
282
- // Check step. Step must be greater than zero
283
- ET_LOG_MSG_AND_RETURN_IF_FALSE (
284
- step > 0 , " slice step must be greater than zero" );
285
-
286
- // The size of src tensor should follow these rules:
287
- // - src.size(i) shall equal to input.size(i) if i != dim,
288
- // - src.size(dim) shall equal to num_values
289
- for (size_t d = 0 ; d < input.dim () - 1 ; d++) {
290
- if (d != dim) {
291
- ET_LOG_AND_RETURN_IF_FALSE (
292
- tensors_have_same_size_at_dims (input, d, src, d));
293
- } else {
294
- ET_LOG_MSG_AND_RETURN_IF_FALSE (
295
- src.size (d) == num_values,
296
- " input.size(%zu) %zd != num_values %" PRId64 " | dim = %" PRId64 " )" ,
297
- d,
298
- input.size (d),
299
- num_values,
300
- dim);
301
- }
302
- }
303
-
304
- return true ;
305
- }
306
-
307
- int64_t adjust_slice_indices (
308
- int64_t dim_length,
309
- int64_t * start,
310
- int64_t * end,
311
- int64_t step) {
312
- int64_t num_values = 0 ;
313
-
314
- // Update start and end index
315
- // First convert it to c++ style from python style if needed.
316
- // The start index is using python style E.g., for the shape {2, 3, 4},
317
- // dim = -1 would refer to dim[2], dim = -2 would refer to dim[1], and so on.
318
- *start = *start < 0 ? *start + dim_length : *start;
319
- *end = *end < 0 ? *end + dim_length : *end;
320
- // Second, if start or end still negative, which means user want to start or
321
- // end slicing from very beginning, so set it to zero
322
- *start = *start < 0 ? 0 : *start;
323
- *end = *end < 0 ? 0 : *end;
324
- // Last, if start or end larger than maximum value (dim_length - 1), indicates
325
- // user want to start slicing after end or slicing until the end, so update it
326
- // to dim_length
327
- *start = *start > dim_length ? dim_length : *start;
328
- *end = *end > dim_length ? dim_length : *end;
329
-
330
- if (*start >= dim_length || *end <= 0 || *start >= *end) {
331
- // Set num_values to 0 if interval [start, end) is non-exist or do not
332
- // overlap with [0, dim_length)
333
- num_values = 0 ;
334
- } else {
335
- // Update num_values to min(max_num_values, num_values)
336
- num_values = (*end - 1 - *start) / step + 1 ;
337
- }
338
- return num_values;
339
- }
340
-
341
264
} // namespace executor
342
265
} // namespace torch
0 commit comments