modeci_mdf.functions.onnx.slice

modeci_mdf.functions.onnx.slice(*args, **kwargs)

Produces a slice of the input tensor along multiple axes. Similar to numpy: https://numpy.org/doc/stable/user/basics.indexing.html?highlight=slice#slicing-and-striding

Slice uses the starts, ends, axes and steps inputs to select a sub-tensor of its input data tensor.

An effective start[i], end[i], and step[i] must be computed for each i in [0, … r-1] where r = rank(input) as follows:

If axes are omitted, they are set to [0, …, r-1]. If steps are omitted, they are set to [1, …, 1] of length len(starts)

The effective values are initialized as start[i] = 0, end[i] = dims[i] where dims are the dimensions of input and `step[i] = `1.

All negative elements of axes are made non-negatve by adding r to them, where r =rank(input).

All negative values in starts[i] and ends[i] have dims[axes[i]] added to them, where dims are the dimensions of input. Then start[axes[i]] is the adjusted starts[i] is clamped into the range [0, dims[axes[i]]] for positive stepping and [0, dims[axes[i]]-1] for negative stepping.

The clamping for the adjusted ends[i] depends on the sign of steps[i] and must accommodate copying 0 through dims[axes[i]] elements, so for positive stepping end[axes[i]] is clamped to [0, dims[axes[i]]], while for negative stepping it is clamped to [-1, dims[axes[i]]-1].

Finally, step[axes[i]] = steps[i].

For slicing to the end of a dimension with unknown size, it is recommended to pass in INT_MAX when slicing forward and ‘INT_MIN’ when slicing backward.

Example 1:
data = [

[1, 2, 3, 4], [5, 6, 7, 8],

] axes = [0, 1] starts = [1, 0] ends = [2, 3] steps = [1, 2] result = [

[5, 7],

]

Example 2:
data = [

[1, 2, 3, 4], [5, 6, 7, 8],

] starts = [0, 1] ends = [-1, 1000] result = [

[2, 3, 4],

]