Slice

Slice  // Produces a sub-tensor of its input.

Description

Takes a slice of an input tensor, i.e., the sub-tensor that resides within a bounding box, optionally with a stride.

Inputs

Name

Element Type

Shape

arg

Any

\(D=D_1, D_2, \ldots, D_n\).

Attributes

Name

Description

lower_bounds

The (inclusive) lower-bound coordinates \(L=L_1, L_2, \ldots, L_n.\)

upper_bounds

The (exclusive) upper-bound coordinates \(U=U_1, U_2, \ldots, U_n.\)

strides

The strides \(S=S_1, S_2, \ldots, S_n\) for the slices. Defaults to 1s.

Outputs

Name

Element Type

Shape

output

Same as arg

\(D'_i=\lceil\frac{U_i-L_i}{S_i}\rceil\).

Mathematical Definition

\[\mathtt{output}_I = \mathtt{arg}_{L+I*S}\]

where \(I=I_1, I_2, \ldots, I_n\) is a coordinate of the output.

C++ Interface

class Slice : public ngraph::op::Op

Takes a slice of an input tensor, i.e., the sub-tensor that resides within a bounding box, optionally with stride.

Public Functions

const std::string &description() const

Get the string name for the type of the node, such as Add or Multiply. The class name, must not contain spaces as it is used for codegen.

Return

A const reference to the node’s type name

Slice()

Constructs a tensor slice operation.

Slice(const Output<Node> &arg, const Coordinate &lower_bounds, const Coordinate &upper_bounds, const Strides &strides)

Constructs a tensor slice operation.

Parameters
  • arg: The tensor to be sliced.

  • lower_bounds: The axiswise lower bounds of the slice (inclusive).

  • upper_bounds: The axiswise upper bounds of the slice (exclusive).

  • strides: The slicing strides; for example, strides of {n,m} means to take every nth row and every mth column of the input matrix.

Slice(const Output<Node> &arg, const Coordinate &lower_bounds, const Coordinate &upper_bounds)

Constructs a tensor slice operation with unit strides; i.e., every element inside the bounding box will be copied to the output slice.

Parameters
  • arg: The tensor to be sliced.

  • lower_bounds: The axiswise lower bounds of the slice (inclusive).

  • upper_bounds: The axiswise upper bounds of the slice (exclusive).

void validate_and_infer_types()

Throws if the node is invalid.

const Coordinate &get_lower_bounds() const

Return

The inclusive lower-bound coordinates.

const Coordinate &get_upper_bounds() const

Return

The exclusive upper-bound coordinates.

const Strides &get_strides() const

Return

The slicing strides.