tvm.relay.op

Relay core operators.

Classes

Op()

A Relay operator definition.

OpPattern

Operator generic patterns

OpStrategy()

Operator strategy

Functions

abs(data)

Compute element-wise absolute of data.

add(lhs, rhs)

Addition with numpy-style broadcasting.

all(data[, axis, keepdims, exclude])

Computes the logical AND of boolean array elements over given axes.

any(data[, axis, keepdims, exclude])

Computes the logical OR of boolean array elements over given axes.

arange(start[, stop, step, dtype])

Return evenly spaced values within a given interval.

argmax(data[, axis, keepdims, exclude])

Returns the indices of the maximum values along an axis.

argmin(data[, axis, keepdims, exclude])

Returns the indices of the minimum values along an axis.

argsort(data[, axis, is_ascend, dtype])

Performs sorting along the given axis and returns an array of indicies having same shape as an input array that index data in sorted order.

argwhere(condition)

Find the indices of elements of a tensor that are non-zero.

atan(data)

Compute elementwise atan of data.

bitwise_and(lhs, rhs)

bitwise AND with numpy-style broadcasting.

bitwise_not(data)

Compute element-wise bitwise not of data.

bitwise_or(lhs, rhs)

bitwise OR with numpy-style broadcasting.

bitwise_xor(lhs, rhs)

bitwise XOR with numpy-style broadcasting.

broadcast_to(data, shape)

Return a scalar value array with the same type, broadcast to the provided shape.

broadcast_to_like(data, broadcast_type)

Return a scalar value array with the same shape and type as the input array.

cast(data, dtype)

Cast input tensor to data type.

cast_like(data, dtype_like)

Cast input tensor to data type of another tensor.

ceil(data)

Compute element-wise ceil of data.

clip(a, a_min, a_max)

Clip the elements in a between a_min and a_max.

collapse_sum_like(data, collapse_type)

Return a scalar value array with the same shape and type as the input array.

concatenate(data, axis)

Concatenate the input tensors along the given axis.

const(value[, dtype])

Create a constant value.

copy(data)

Copy a tensor.

cos(data)

Compute elementwise cos of data.

debug(expr[, debug_func])

The main entry point to the debugger.

device_copy(data, src_dev, dst_dev)

Copy data from the source device to the destination device.

divide(lhs, rhs)

Division with numpy-style broadcasting.

equal(lhs, rhs)

Broadcasted elementwise test for (lhs == rhs).

erf(data)

Compute elementwise error function of data.

exp(data)

Compute elementwise exp of data.

expand_dims(data, axis[, num_newaxis])

Insert num_newaxis axises at the position given by axis.

floor(data)

Compute element-wise floor of data.

floor_divide(lhs, rhs)

Floor division with numpy-style broadcasting.

floor_mod(lhs, rhs)

Floor mod with numpy-style broadcasting.

full(fill_value[, shape, dtype])

Fill array with scalar value.

full_like(data, fill_value)

Return a scalar value array with the same shape and type as the input array.

gather_nd(data, indices)

Gather elements or slices from data and store to a tensor whose shape is defined by indices.

get(op_name)

Get the Op for a given name

greater(lhs, rhs)

Broadcasted elementwise test for (lhs > rhs).

greater_equal(lhs, rhs)

Broadcasted elementwise test for (lhs >= rhs).

isfinite(data)

Compute element-wise finiteness of data.

isinf(data)

Compute element-wise infiniteness of data.

layout_transform(data, src_layout, dst_layout)

Transform the layout of a tensor

left_shift(lhs, rhs)

Left shift with numpy-style broadcasting.

less(lhs, rhs)

Broadcasted elementwise test for (lhs < rhs).

less_equal(lhs, rhs)

Broadcasted elementwise test for (lhs <= rhs).

log(data)

Compute elementwise log of data.

logical_and(lhs, rhs)

logical AND with numpy-style broadcasting.

logical_not(data)

Compute element-wise logical not of data.

logical_or(lhs, rhs)

logical OR with numpy-style broadcasting.

max(data[, axis, keepdims, exclude])

Computes the max of array elements over given axes.

maximum(lhs, rhs)

Maximum with numpy-style broadcasting.

mean(data[, axis, keepdims, exclude])

Computes the mean of array elements over given axes.

mean_std(data[, axis, keepdims, exclude])

Computes the mean and standard deviation of data over given axes.

mean_variance(data[, axis, keepdims, exclude])

Computes the mean and variance of data over given axes.

min(data[, axis, keepdims, exclude])

Computes the min of array elements over given axes.

minimum(lhs, rhs)

Minimum with numpy-style broadcasting.

mod(lhs, rhs)

Mod with numpy-style broadcasting.

multiply(lhs, rhs)

Multiplication with numpy-style broadcasting.

ndarray_size(data[, dtype])

Get number of elements of input tensor.

negative(data)

Compute element-wise negative of data.

not_equal(lhs, rhs)

Broadcasted elementwise test for (lhs != rhs).

one_hot(indices, on_value, off_value, depth, …)

Returns a one-hot tensor where the locations repsented by indices take value on_value, other locations take value off_value.

ones(shape, dtype)

Fill array with ones.

ones_like(data)

Returns an array of ones, with same type and shape as the input.

power(lhs, rhs)

Power with numpy-style broadcasting.

prod(data[, axis, keepdims, exclude])

Computes the products of array elements over given axes.

register(op_name, attr_key[, value, level])

Register an operator property of an operator.

register_alter_op_layout(op_name[, …])

Register alter op layout function for an op

register_compute(op_name[, compute, level])

Register compute function for an op.

register_external_compiler(op_name[, …])

Register the external compiler for an op.

register_gradient(op_name[, fgradient, level])

Register operator pattern for an op.

register_legalize(op_name[, legal_op, level])

Register legal transformation function for an op

register_pattern(op_name, pattern[, level])

Register operator pattern for an op.

reinterpret(data, dtype)

Reinterpret input tensor to data type.

repeat(data, repeats, axis)

Repeats elements of an array.

reshape(data, newshape)

Reshape the input array.

reshape_like(data, shape_like)

Reshapes the input array by the size of another array.

reverse(data, axis)

Reverses the order of elements along given axis while preserving array shape.

reverse_reshape(data, newshape)

Reshapes the input array where the special values are inferred from right to left.

right_shift(lhs, rhs)

Right shift with numpy-style broadcasting.

round(data)

Compute element-wise round of data.

rsqrt(data)

Compute elementwise rsqrt of data.

sequence_mask(data, valid_length[, …])

Sets all elements outside the expected length of the sequence to a constant value.

shape_of(data[, dtype])

Get shape of a tensor.

sigmoid(data)

Compute elementwise sigmoid of data.

sign(data)

Compute element-wise absolute of data.

sin(data)

Compute elementwise sin of data.

slice_like(data, shape_like[, axes])

Slice the first input with respect to the second input.

split(data, indices_or_sections[, axis])

Split input tensor along axis by sections or indices.

sqrt(data)

Compute elementwise sqrt of data.

squeeze(data[, axis])

Squeeze axes in the array.

stack(data, axis)

Join a sequence of arrays along a new axis.

std(data[, axis, keepdims, exclude])

Computes the standard deviation of data over given axes.

strided_set(data, v, begin, end[, strides])

Strided set of an array.

strided_slice(data, begin, end[, strides])

Strided slice of an array.

subtract(lhs, rhs)

Subtraction with numpy-style broadcasting.

sum(data[, axis, keepdims, exclude])

Computes the sum of array elements over given axes.

take(data, indices[, axis, mode])

Take elements from an array along an axis.

tan(data)

Compute elementwise tan of data.

tanh(data)

Compute element-wise tanh of data.

tile(data, reps)

Repeats the whole array multiple times.

topk(data[, k, axis, ret_type, is_ascend, dtype])

Get the top k elements in an input tensor along the given axis.

transpose(data[, axes])

Permutes the dimensions of an array.

trunc(data)

Compute element-wise trunc of data.

unravel_index(indices, shape)

Convert a flat index or array of flat indices into a tuple of coordinate arrays.

variance(data[, axis, keepdims, exclude])

Computes the variance of data over given axes.

where(condition, x, y)

Selecting elements from either x or y depending on the value of the condition.

zeros(shape, dtype)

Fill array with zeros.

zeros_like(data)

Returns an array of zeros, with same type and shape as the input.

tvm.relay.op.get(op_name)

Get the Op for a given name

Parameters

op_name (str) – The operator name

Returns

op – The op of the corresponding name

Return type

Op

tvm.relay.op.register(op_name, attr_key, value=None, level=10)

Register an operator property of an operator.

Parameters
  • op_name (str) – The name of operator

  • attr_key (str) – The attribute name.

  • value (object, optional) – The value to set

  • level (int, optional) – The priority level

Returns

fregister – Register function if value is not specified.

Return type

function

tvm.relay.op.register_compute(op_name, compute=None, level=10)

Register compute function for an op.

Parameters
  • op_name (str) – The name of the op.

  • compute (function (attrs: Attrs, inputs: List[Tensor], out_type: Type)) – -> List[Tensor] The compute function.

  • level (int) – The priority level

tvm.relay.op.register_gradient(op_name, fgradient=None, level=10)

Register operator pattern for an op.

Parameters
  • op_name (str) – The name of the op.

  • fgradient (function (orig_expr : Expr, output_grad : Expr) -> new_expr : Expr) – The gradient being used.

  • level (int) – The priority level

tvm.relay.op.register_pattern(op_name, pattern, level=10)

Register operator pattern for an op.

Parameters
  • op_name (str) – The name of the op.

  • pattern (int) – The pattern being used.

  • level (int) – The priority level

tvm.relay.op.register_alter_op_layout(op_name, alter_layout=None, level=10)

Register alter op layout function for an op

Parameters
  • op_name (str) – The name of the operator

  • alter_layout (function (attrs: Attrs, inputs: List[Expr]) -> new_expr: Expr) – The function for changing the layout or replacing the operator

  • level (int) – The priority level

tvm.relay.op.register_legalize(op_name, legal_op=None, level=10)

Register legal transformation function for an op

Parameters
  • op_name (str) – The name of the operator

  • legal_op (function (attrs: Attrs, inputs: List[Expr]) -> new_expr: Expr) – The function for transforming an expr to another expr.

  • level (int) – The priority level

class tvm.relay.op.Op

A Relay operator definition.

Methods

get_attr(attr_name)

Get additional attribute about the operator.

reset_attr(attr_name)

Reset attribute about the operator.

set_attr(attr_name, value[, plevel])

Set attribute about the operator.

get_attr(attr_name)

Get additional attribute about the operator.

Parameters

attr_name (str) – The attribute name.

Returns

value – The attribute value

Return type

object

set_attr(attr_name, value, plevel=10)

Set attribute about the operator.

Parameters
  • attr_name (str) – The attribute name

  • value (object) – The attribute value

  • plevel (int) – The priority level

reset_attr(attr_name)

Reset attribute about the operator.

Parameters

attr_name (str) – The attribute name

class tvm.relay.op.OpPattern

Operator generic patterns

See also

top.tag

Contains explanation of the tag type.

class tvm.relay.op.OpStrategy

Operator strategy

Methods

add_implementation(compute, schedule[, …])

Add an implementation to the strategy

add_implementation(compute, schedule, name='default', plevel=10)

Add an implementation to the strategy

Parameters
  • compute (function (attrs: Attrs, inputs: List[Tensor], out_type: Type)) – -> List[Tensor] The compute function.

  • schedule (function (attrs: Attrs, outs: List[Tensor], target:Target) -> Schedule) – The schedule function.

  • name (str) – The name of implementation.

  • plevel (int) – The priority level of implementation.

tvm.relay.op.debug(expr, debug_func=None)

The main entry point to the debugger.

tvm.relay.op.register_external_compiler(op_name, fexternal=None, level=10)

Register the external compiler for an op.

Parameters
  • op_name (str) – The name of the operator.

  • fexternal (function (attrs: Attrs, args: List[Expr], compiler: str)) – -> new_expr: Expr The function for wrapping a call expr with compiler_begin and compiler_end.

  • level (int) – The priority level

tvm.relay.op.abs(data)

Compute element-wise absolute of data.

Parameters

data (relay.Expr) – The input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.add(lhs, rhs)

Addition with numpy-style broadcasting.

Parameters
  • lhs (relay.Expr) – The left hand side input data

  • rhs (relay.Expr) – The right hand side input data

Returns

result – The computed result.

Return type

relay.Expr

Examples

x = relay.Var("a") # shape is [2, 3]
y = relay.Var("b") # shape is [2, 1]
z = relay.add(x, y)  # result shape is [2, 3]
tvm.relay.op.all(data, axis=None, keepdims=False, exclude=False)

Computes the logical AND of boolean array elements over given axes.

Parameters
  • data (relay.Expr) – The input boolean tensor

  • axis (None or int or tuple of int) – Axis or axes along which a sum is performed. The default, axis=None, will sum all of the elements of the input array. If axis is negative it counts from the last to the first axis.

  • keepdims (bool) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.

  • exclude (bool) – If exclude is true, reduction will be performed on the axes that are NOT in axis instead.

Returns

result – The computed result.

Return type

relay.Expr

Examples

data = relay.Constant(tvm.nd.array([[[ True,  True,  True],
                                   [ True,  True,  True],
                                   [False,  True, False]],
                                  [[ True, False, False],
                                   [ True,  True, False],
                                   [False,  True,  True]]]))

relay.all(data, axis=1)
# [[False,  True, False],
# [False, False, False]]

relay.all(data, axis=0)
# [[ True, False, False],
# [ True,  True, False],
# [False,  True, False]]
tvm.relay.op.any(data, axis=None, keepdims=False, exclude=False)

Computes the logical OR of boolean array elements over given axes.

Parameters
  • data (relay.Expr) – The input boolean tensor

  • axis (None or int or tuple of int) – Axis or axes along which a sum is performed. The default, axis=None, will sum all of the elements of the input array. If axis is negative it counts from the last to the first axis.

  • keepdims (bool) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.

  • exclude (bool) – If exclude is true, reduction will be performed on the axes that are NOT in axis instead.

Returns

result – The computed result.

Return type

relay.Expr

Examples

data = relay.Constant(tvm.nd.array([[[ True,  True,  True],
                                    [ True,  True,  True],
                                    [False,  True, False]],
                                    [[ True, False, False],
                                    [ True,  True, False],
                                    [False,  True,  True]]]))

relay.any(data, axis=1)
# [[True, True, True],
# [True,  True, True]]

relay.any(data, axis=0)
# [[ True, True, True],
# [ True,  True, True],
# [False,  True, True]]
tvm.relay.op.arange(start, stop=None, step=None, dtype='float32')

Return evenly spaced values within a given interval.

Note

Similar to numpy.arange, when only one argument is given, it is used as stop instead of start while start takes default value 0.

Warning: Undefined behavior when dtype is incompatible with start/stop/step. It could lead to different results compared to numpy, MXNet, pytorch, etc.

Parameters
  • start (tvm.Expr, optional) – Start of interval. The interval includes this value. The default start value is 0.

  • stop (tvm.Expr) – Stop of interval. The interval does not include this value.

  • step (tvm.Expr, optional) – Spacing between values. The default step size is 1.

  • dtype (str, optional) – The target data type.

Returns

result – The resulting tensor.

Return type

relay.Expr

Examples

relay.arange(5) = [0, 1, 2, 3, 4]
relay.arange(1, 5) = [1, 2, 3, 4]
relay.arange(1, 5, 1.5) = [1, 2.5, 4]
tvm.relay.op.argmax(data, axis=None, keepdims=False, exclude=False)

Returns the indices of the maximum values along an axis.

Parameters
  • data (relay.Expr) – The input data

  • axis (None or int or tuple of int) – Axis or axes along which a argmax operation is performed. The default, axis=None, will find the indices of the maximum element of the elements of the input array. If axis is negative it counts from the last to the first axis.

  • keepdims (bool) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.

  • exclude (bool) – If exclude is true, reduction will be performed on the axes that are NOT in axis instead.

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.argmin(data, axis=None, keepdims=False, exclude=False)

Returns the indices of the minimum values along an axis.

Parameters
  • data (relay.Expr) – The input data

  • axis (None or int or tuple of int) – Axis or axes along which a argmin operation is performed. The default, axis=None, will find the indices of minimum element all of the elements of the input array. If axis is negative it counts from the last to the first axis.

  • keepdims (bool) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.

  • exclude (bool) – If exclude is true, reduction will be performed on the axes that are NOT in axis instead.

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.argsort(data, axis=-1, is_ascend=1, dtype='int32')

Performs sorting along the given axis and returns an array of indicies having same shape as an input array that index data in sorted order.

Parameters
  • data (relay.Expr) – The input data tensor.

  • valid_count (tvm.te.Tensor) – The number of valid elements to be sorted.

  • axis (int, optional) – Axis long which to sort the input tensor.

  • is_ascend (boolean, optional) – Whether to sort in ascending or descending order.

  • dtype (string, optional) – The data type of the output indices.

Returns

out – Tensor with same shape as data.

Return type

relay.Expr

tvm.relay.op.argwhere(condition)

Find the indices of elements of a tensor that are non-zero.

Parameters

condition (relay.Expr) – The input condition tensor.

Returns

out – Tensor with the indices of elements that are non-zero.

Return type

relay.Expr

Examples

condition = [[True, False], [False, True]]
relay.argwhere(condition) = [[0, 0], [1, 1]]
tvm.relay.op.atan(data)

Compute elementwise atan of data.

Parameters

data (relay.Expr) – The input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.bitwise_and(lhs, rhs)

bitwise AND with numpy-style broadcasting.

Parameters
  • lhs (relay.Expr) – The left hand side input data

  • rhs (relay.Expr) – The right hand side input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.bitwise_not(data)

Compute element-wise bitwise not of data.

Parameters

data (relay.Expr) – The input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.bitwise_or(lhs, rhs)

bitwise OR with numpy-style broadcasting.

Parameters
  • lhs (relay.Expr) – The left hand side input data

  • rhs (relay.Expr) – The right hand side input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.bitwise_xor(lhs, rhs)

bitwise XOR with numpy-style broadcasting.

Parameters
  • lhs (relay.Expr) – The left hand side input data

  • rhs (relay.Expr) – The right hand side input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.broadcast_to(data, shape)

Return a scalar value array with the same type, broadcast to the provided shape.

Parameters
  • data (relay.Expr) – The input tensor.

  • shape (shape) – Provide the shape to broadcast to.

Returns

result – The resulting tensor.

Return type

relay.Expr

tvm.relay.op.broadcast_to_like(data, broadcast_type)

Return a scalar value array with the same shape and type as the input array.

Parameters
  • data (relay.Expr) – The input tensor.

  • broadcast_type (relay.Expr) – Provide the type to broadcast to.

Returns

result – The resulting tensor.

Return type

relay.Expr

tvm.relay.op.cast(data, dtype)

Cast input tensor to data type.

Parameters
  • data (relay.Expr) – The input data to the operator.

  • dtype (str) – The target data type

Returns

result – The casted result.

Return type

relay.Expr

tvm.relay.op.cast_like(data, dtype_like)

Cast input tensor to data type of another tensor. :param data: The input data to the operator. :type data: relay.Expr :param dtype_like: The tensor to cast to. :type dtype_like: relay.Expr

Returns

result – The casted result.

Return type

relay.Expr

tvm.relay.op.ceil(data)

Compute element-wise ceil of data.

Parameters

data (relay.Expr) – The input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.clip(a, a_min, a_max)

Clip the elements in a between a_min and a_max. a_min and a_max are cast to a’s dtype.

Parameters
  • a (relay.Expr) – The input tensor.

  • a_min (float) – The clip minimum.

  • a_max (float) – The clip maximum.

Returns

resulta with elements clipped between a_min and a_max.

Return type

relay.Expr

Examples

x = relay.Constant(tvm.nd.array([0, 1, 5, 3, 4, 2]))
relay.clip(x, 1., 4.)
# [1, 1, 4, 3, 4, 2]
tvm.relay.op.collapse_sum_like(data, collapse_type)

Return a scalar value array with the same shape and type as the input array.

Parameters
  • data (relay.Expr) – The input tensor.

  • collapse_type (relay.Expr) – Provide the type to collapse to.

Returns

result – The resulting tensor.

Return type

relay.Expr

tvm.relay.op.concatenate(data, axis)

Concatenate the input tensors along the given axis.

Parameters
  • data (Union(List[relay.Expr], Tuple[relay.Expr])) – A list of tensors.

  • axis (int) – The axis along which the tensors are concatenated.

Returns

result – The concatenated tensor.

Return type

relay.Expr

tvm.relay.op.const(value, dtype=None)

Create a constant value.

Parameters

Note

When dtype is None, we use the following rule:

  • int maps to “int32”

  • float maps to “float32”

  • bool maps to “bool”

  • other using the same default rule as numpy.

tvm.relay.op.copy(data)

Copy a tensor.

Parameters

data (relay.Expr) – The tensor to be copied.

Returns

result – The copied result.

Return type

relay.Expr

tvm.relay.op.cos(data)

Compute elementwise cos of data.

Parameters

data (relay.Expr) – The input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.device_copy(data, src_dev, dst_dev)

Copy data from the source device to the destination device. This operator helps data transferring between difference contexts for heterogeneous execution.

Parameters
  • data (tvm.relay.Expr) – The tensor to be copied.

  • src_dev (Union[TVMContext, str]) – The source device where the data is copied from.

  • dst_dev (Union[TVMContext, str]) – The destination device where the data is copied to.

Returns

result – The copied result.

Return type

tvm.relay.Expr

tvm.relay.op.divide(lhs, rhs)

Division with numpy-style broadcasting.

Parameters
  • lhs (relay.Expr) – The left hand side input data

  • rhs (relay.Expr) – The right hand side input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.equal(lhs, rhs)

Broadcasted elementwise test for (lhs == rhs).

Parameters
  • lhs (relay.Expr) – The left hand side input data

  • rhs (relay.Expr) – The right hand side input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.erf(data)

Compute elementwise error function of data.

Parameters

data (relay.Expr) – The input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.exp(data)

Compute elementwise exp of data.

Parameters

data (relay.Expr) – The input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.expand_dims(data, axis, num_newaxis=1)

Insert num_newaxis axises at the position given by axis.

Parameters
  • data (relay.Expr) – The input data to the operator.

  • axis (int) – The axis at which the input array is expanded. Should lie in range [-data.ndim - 1, data.ndim]. If axis < 0, it is the first axis inserted; If axis >= 0, it is the last axis inserted in Python’s negative indexing.

  • num_newaxis (int) – Number of axes to be inserted. Should be >= 0.

Returns

result – The reshaped result.

Return type

relay.Expr

tvm.relay.op.floor(data)

Compute element-wise floor of data.

Parameters

data (relay.Expr) – The input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.floor_divide(lhs, rhs)

Floor division with numpy-style broadcasting.

Parameters
  • lhs (relay.Expr) – The left hand side input data

  • rhs (relay.Expr) – The right hand side input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.floor_mod(lhs, rhs)

Floor mod with numpy-style broadcasting.

Parameters
  • lhs (relay.Expr) – The left hand side input data

  • rhs (relay.Expr) – The right hand side input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.full(fill_value, shape=(), dtype='')

Fill array with scalar value.

Parameters
  • fill_value (relay.Expr) – The value to fill. Must be a scalar.

  • shape (tuple of int) – The shape of the target.

  • dtype (data type, optional (defaults to data type of the fill value)) – The data type of the target.

Returns

result – The resulting tensor.

Return type

relay.Expr

tvm.relay.op.full_like(data, fill_value)

Return a scalar value array with the same shape and type as the input array.

Parameters
  • data (relay.Expr) – The input tensor.

  • fill_value (relay.Expr) – The scalar value to fill.

Returns

result – The resulting tensor.

Return type

relay.Expr

tvm.relay.op.gather_nd(data, indices)

Gather elements or slices from data and store to a tensor whose shape is defined by indices.

Parameters
  • data (relay.Expr) – The input data to the operator.

  • indices (relay.Expr) – The shape of output tensor.

Returns

ret – The computed result.

Return type

relay.Expr

Examples

data = [[0, 1], [2, 3]]
indices = [[1, 1, 0], [0, 1, 0]]
relay.gather_nd(data, indices) = [2, 3, 0]

data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
indices = [[0, 1], [1, 0]]
relay.gather_nd(data, indices) = [[3, 4], [5, 6]]
tvm.relay.op.greater(lhs, rhs)

Broadcasted elementwise test for (lhs > rhs).

Parameters
  • lhs (relay.Expr) – The left hand side input data

  • rhs (relay.Expr) – The right hand side input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.greater_equal(lhs, rhs)

Broadcasted elementwise test for (lhs >= rhs).

Parameters
  • lhs (relay.Expr) – The left hand side input data

  • rhs (relay.Expr) – The right hand side input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.isfinite(data)

Compute element-wise finiteness of data.

Parameters

data (relay.Expr) – The input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.isinf(data)

Compute element-wise infiniteness of data.

Parameters

data (relay.Expr) – The input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.layout_transform(data, src_layout, dst_layout)

Transform the layout of a tensor

Parameters
  • data (relay.Expr) – The source tensor to be transformed

  • src_layout (str) – The source layout. (e.g NCHW)

  • dst_layout (str) – The destination layout. (e.g. NCHW16c)

Returns

ret – The transformed tensor.

Return type

relay.Expr

tvm.relay.op.left_shift(lhs, rhs)

Left shift with numpy-style broadcasting.

Parameters
  • lhs (relay.Expr) – The left hand side input data

  • rhs (relay.Expr) – The right hand side input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.less(lhs, rhs)

Broadcasted elementwise test for (lhs < rhs).

Parameters
  • lhs (relay.Expr) – The left hand side input data

  • rhs (relay.Expr) – The right hand side input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.less_equal(lhs, rhs)

Broadcasted elementwise test for (lhs <= rhs).

Parameters
  • lhs (relay.Expr) – The left hand side input data

  • rhs (relay.Expr) – The right hand side input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.log(data)

Compute elementwise log of data.

Parameters

data (relay.Expr) – The input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.logical_and(lhs, rhs)

logical AND with numpy-style broadcasting.

Parameters
  • lhs (relay.Expr) – The left hand side input data

  • rhs (relay.Expr) – The right hand side input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.logical_not(data)

Compute element-wise logical not of data.

Parameters

data (relay.Expr) – The input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.logical_or(lhs, rhs)

logical OR with numpy-style broadcasting.

Parameters
  • lhs (relay.Expr) – The left hand side input data

  • rhs (relay.Expr) – The right hand side input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.max(data, axis=None, keepdims=False, exclude=False)

Computes the max of array elements over given axes.

Parameters
  • data (relay.Expr) – The input data

  • axis (None or int or tuple of int) – Axis or axes along which the max operation is performed. The default, axis=None, will find the max element from all of the elements of the input array. If axis is negative it counts from the last to the first axis.

  • keepdims (bool) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.

  • exclude (bool) – If exclude is true, reduction will be performed on the axes that are NOT in axis instead.

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.maximum(lhs, rhs)

Maximum with numpy-style broadcasting.

Parameters
  • lhs (relay.Expr) – The left hand side input data

  • rhs (relay.Expr) – The right hand side input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.mean(data, axis=None, keepdims=False, exclude=False)

Computes the mean of array elements over given axes.

Parameters
  • data (relay.Expr) – The input data

  • axis (None or int or tuple of int) – Axis or axes along which a mean operation is performed. The default, axis=None, will compute the mean of all elements in the input array. If axis is negative it counts from the last to the first axis.

  • keepdims (bool) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.

  • exclude (bool) – If exclude is true, reduction will be performed on the axes that are NOT in axis instead.

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.mean_std(data, axis=None, keepdims=False, exclude=False)

Computes the mean and standard deviation of data over given axes.

Parameters
  • data (relay.Expr) – The input data

  • axis (None or int or tuple of int) – Axis or axes along which a mean and standard deviation operation is performed. The default, axis=None, will compute the mean and standard deviation of all elements in the input array. If axis is negative it counts from the last to the first axis.

  • keepdims (bool) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.

  • exclude (bool) – If exclude is true, reduction will be performed on the axes that are NOT in axis instead.

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.mean_variance(data, axis=None, keepdims=False, exclude=False)

Computes the mean and variance of data over given axes.

Parameters
  • data (relay.Expr) – The input data

  • axis (None or int or tuple of int) – Axis or axes along which a mean and variance operation is performed. The default, axis=None, will compute the mean and variance of all elements in the input array. If axis is negative it counts from the last to the first axis.

  • keepdims (bool) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.

  • exclude (bool) – If exclude is true, reduction will be performed on the axes that are NOT in axis instead.

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.min(data, axis=None, keepdims=False, exclude=False)

Computes the min of array elements over given axes.

Parameters
  • data (relay.Expr) – The input data

  • axis (None or int or tuple of int) – Axis or axes along which a minimum operation is performed. The default, axis=None, will find the minimum element from all of the elements of the input array. If axis is negative it counts from the last to the first axis.

  • keepdims (bool) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.

  • exclude (bool) – If exclude is true, reduction will be performed on the axes that are NOT in axis instead.

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.minimum(lhs, rhs)

Minimum with numpy-style broadcasting.

Parameters
  • lhs (relay.Expr) – The left hand side input data

  • rhs (relay.Expr) – The right hand side input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.mod(lhs, rhs)

Mod with numpy-style broadcasting.

Parameters
  • lhs (relay.Expr) – The left hand side input data

  • rhs (relay.Expr) – The right hand side input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.multiply(lhs, rhs)

Multiplication with numpy-style broadcasting.

Parameters
  • lhs (relay.Expr) – The left hand side input data

  • rhs (relay.Expr) – The right hand side input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.ndarray_size(data, dtype='int32')

Get number of elements of input tensor.

Parameters
  • data (tvm.relay.Expr) – The input tensor.

  • dtype (str, optional) – The target data type.

Returns

result – The number of elements of input tensor.

Return type

tvm.relay.Expr

tvm.relay.op.negative(data)

Compute element-wise negative of data.

Parameters

data (relay.Expr) – The input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.not_equal(lhs, rhs)

Broadcasted elementwise test for (lhs != rhs).

Parameters
  • lhs (relay.Expr) – The left hand side input data

  • rhs (relay.Expr) – The right hand side input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.one_hot(indices, on_value, off_value, depth, axis, dtype)

Returns a one-hot tensor where the locations repsented by indices take value on_value, other locations take value off_value. Final dimension is <indices outer dimensions> x depth x <indices inner dimensions>.

Parameters
  • indices (relay.Expr) – Locations to set to on_value.

  • on_value (relay.Expr) – Value to fill at indices.

  • off_value (relay.Expr) – Value to fill at all other positions besides indices.

  • depth (int) – Depth of the one-hot dimension.

  • axis (int) – Axis to fill.

  • dtype (str) – Data type of the output tensor.

Returns

ret – The one-hot tensor.

Return type

relay.Expr

Examples

indices = [0, 1, 2]

relay.one_hot(indices, 3) =
    [[1, 0, 0],
     [0, 1, 0],
     [0, 0, 1]]
tvm.relay.op.ones(shape, dtype)

Fill array with ones.

Parameters
  • shape (tuple of int) – The shape of the target.

  • dtype (data type) – The data type of the target.

Returns

result – The resulting tensor.

Return type

relay.Expr

tvm.relay.op.ones_like(data)

Returns an array of ones, with same type and shape as the input.

Parameters

data (relay.Expr) – The input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.power(lhs, rhs)

Power with numpy-style broadcasting.

Parameters
  • lhs (relay.Expr) – The left hand side input data

  • rhs (relay.Expr) – The right hand side input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.prod(data, axis=None, keepdims=False, exclude=False)

Computes the products of array elements over given axes.

Parameters
  • data (relay.Expr) – The input data

  • axis (None or int or tuple of int) – Axis or axes along which a product is performed. The default, axis=None, will find the indices of minimum element all of the elements of the input array. If axis is negative it counts from the last to the first axis.

  • keepdims (bool) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.

  • exclude (bool) – If exclude is true, reduction will be performed on the axes that are NOT in axis instead.

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.reinterpret(data, dtype)

Reinterpret input tensor to data type.

Parameters
  • data (relay.Expr) – The input data to the operator.

  • dtype (str) – The target data type

Returns

result – The reinterpreted result.

Return type

relay.Expr

tvm.relay.op.repeat(data, repeats, axis)

Repeats elements of an array. By default, repeat flattens the input array into 1-D and then repeats the elements.

repeatsint

The number of repetitions for each element.

axis: int

The axis along which to repeat values. The negative numbers are interpreted counting from the backward. By default, use the flattened input array, and return a flat output array.

Returns

ret – The computed result.

Return type

relay.Expr

Examples

x = [[1, 2], [3, 4]]
relay.repeat(x, repeats=2) = [1., 1., 2., 2., 3., 3., 4., 4.]

relay.repeat(x, repeats=2, axis=1) = [[1., 1., 2., 2.],
                                      [3., 3., 4., 4.]]
tvm.relay.op.reshape(data, newshape)

Reshape the input array.

To give user more convenience in without doing manual shape inference, some dimensions of the shape can take special values from the set {0, -1, -2, -3, -4}. The significance of each is explained below:

0 copy this dimension from the input to the output shape.

data.shape = (2,3,4), newshape = (4,0,2), result.shape = (4,3,2)
data.shape = (2,3,4), newshape = (2,0,0), result.shape = (2,3,4)

-1 infers the dimension of the output shape by using the remainder of the input dimensions keeping the size of the new array same as that of the input array. At most one dimension of shape can be -1.

data.shape = (2,3,4), newshape = (6,1,-1), result.shape = (6,1,4)
data.shape = (2,3,4), newshape = (3,-1,8), result.shape = (3,1,8)
data.shape = (2,3,4), newshape = (-1,), result.shape = (24,)

-2 copy all/remainder of the input dimensions to the output shape.

data.shape = (2,3,4), newshape = (-2,), result.shape = (2,3,4)
data.shape = (2,3,4), newshape = (2,-2), result.shape = (2,3,4)
data.shape = (2,3,4), newshape = (-2,1,1), result.shape = (2,3,4,1,1)

-3 use the product of two consecutive dimensions of the input shape as the output dimension.

data.shape = (2,3,4), newshape = (-3,4), result.shape = (6,4)
data.shape = (2,3,4,5), newshape = (-3,-3), result.shape = (6,20)
data.shape = (2,3,4), newshape = (0,-3), result.shape = (2,12)
data.shape = (2,3,4), newshape = (-3,-2), result.shape = (6,4)

-4 split one dimension of the input into two dimensions passed subsequent to -4 in shape (can contain -1).

data.shape = (2,3,4), newshape = (-4,1,2,-2), result.shape = (1,2,3,4)
data.shape = (2,3,4), newshape = (2,-4,-1,3,-2), result.shape = (2,1,3,4)
Parameters
  • data (relay.Expr) – The input data to the operator.

  • newshape (Union[int, Tuple[int], List[int]]) – The new shape. Should be compatible with the original shape.

Returns

result – The reshaped result.

Return type

relay.Expr

tvm.relay.op.reshape_like(data, shape_like)

Reshapes the input array by the size of another array. For an input array with shape (d1, d2, ..., dk), reshape_like operation reshapes the input array into an output array with the same shape as the second input array.

Note

Sizes for both array should be compatible.

Parameters
  • data (relay.Expr) – The input data to the operator.

  • shape_like (tuple of int) – The new shape. Should be compatible with the original shape.

Returns

ret – The computed result.

Return type

relay.Expr

tvm.relay.op.reverse(data, axis)

Reverses the order of elements along given axis while preserving array shape. By default, repeat flattens the input array into 1-D and then repeats the elements.

Parameters
  • data (relay.Expr) – The input data to the operator.

  • axis (int) – The axis along which to reverse elements.

Returns

ret – The computed result.

Return type

relay.Expr

Examples

x = [[1., 2.], [3., 4.]]
relay.reverse(x, axis=0) = [[3., 4.], [1., 2.]]

relay.reverse(x, axis=1) = [[2., 1.], [4., 3.]]
tvm.relay.op.reverse_reshape(data, newshape)

Reshapes the input array where the special values are inferred from right to left.

The special values have the same semantics as tvm.relay.reshape. The difference is that special values are inferred from right to left. It can be explained in the example below.

data.shape = (10,5,4), newshape = (-1,0), reshape results in (40,5)
data.shape = (10,5,4), newshape = (-1,0), reverse_reshape results in (40,5)
Parameters
  • data (relay.Expr) – The input data to the operator.

  • newshape (Union[int, Tuple[int], List[int]]) – The new shape. Should be compatible with the original shape.

Returns

result – The reshaped result.

Return type

relay.Expr

tvm.relay.op.right_shift(lhs, rhs)

Right shift with numpy-style broadcasting.

Parameters
  • lhs (relay.Expr) – The left hand side input data

  • rhs (relay.Expr) – The right hand side input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.round(data)

Compute element-wise round of data.

Parameters

data (relay.Expr) – The input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.rsqrt(data)

Compute elementwise rsqrt of data.

\[1/sqrt(x)\]
Parameters

data (relay.Expr) – The input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.sequence_mask(data, valid_length, mask_value=0, axis=0)

Sets all elements outside the expected length of the sequence to a constant value.

This function takes an n-dimensional input array of the form [MAX_LENGTH, batch_size, …] or [batch_size, MAX_LENGTH, …] and returns an array of the same shape.

Parameters
  • data (relay.Expr) – The input data.

  • valid_length (relay.Expr) – The expected (valid) length of each sequence in the tensor.

  • mask_value (float) – The masking value.

  • axis (int) – The axis of the length dimension.

Returns

ret – The computed result.

Return type

relay.Expr

Examples

 x = [[[  1.,   2.,   3.], [  4.,   5.,   6.]],
      [[  7.,   8.,   9.], [ 10.,  11.,  12.]],
      [[ 13.,  14.,   15.], [ 16.,  17.,   18.]]]

relay.sequence_mask(x, valid_length=[1, 1]) =
     [[[  1.,   2.,   3.], [  4.,   5.,   6.]],
      [[  0.,   0.,   0.], [  0.,   0.,   0.]],
      [[  0.,   0.,   0.], [  0.,   0.,   0.]]]

relay.sequence_mask(x, valid_length=[2, 3], mask_value=0.1) =
     [[[  1.,   2.,   3.], [  4.,   5.,   6.]],
      [[  7.,   8.,   9.], [  10.,  11.,  12.]],
      [[  0.1,  0.1,  0.1], [  16.,  17.,  18.]]]
tvm.relay.op.shape_of(data, dtype='int32')

Get shape of a tensor.

Parameters
  • data (tvm.relay.Expr) – The input tensor.

  • dtype (str, optional) – The target data type.

Returns

result – The shape tensor.

Return type

tvm.relay.Expr

tvm.relay.op.sigmoid(data)

Compute elementwise sigmoid of data.

Parameters

data (relay.Expr) – The input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.sign(data)

Compute element-wise absolute of data.

Parameters

data (relay.Expr) – The input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.sin(data)

Compute elementwise sin of data.

Parameters

data (relay.Expr) – The input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.slice_like(data, shape_like, axes=None)

Slice the first input with respect to the second input.

For an input array with shape (d1, d2, ..., dk), slice_like operation slices the the input array corresponding size of second array. By default will slice on all axes.

Parameters
  • data (tvm.relay.Expr) – The source array.

  • shape_like (tvm.relay.Expr) – The new shape.

  • axes (Optional[Tuple[int]]) – List of axes on which input data will be sliced according to the corresponding size of the second input. By default will slice on all axes. Negative axes mean counting in reverse.

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.split(data, indices_or_sections, axis=0)

Split input tensor along axis by sections or indices.

If indices_or_sections is an integer, the input will be divided equally along given axis. If such a split is not possible, an error is raised.

If indices_or_sections is a tuple of sorted integers, the entries indicate where along axis the array is split.

Parameters
  • data (relay.Expr) – The source array.

  • indices_or_sections (int or tuple of int) – Indices or sections to split into. Accepts an int or a tuple

  • axis (int, optional) – The axis over which to split.

Returns

ret – The computed result.

Return type

relay.Tuple([relay.Expr, relay.Expr])

tvm.relay.op.sqrt(data)

Compute elementwise sqrt of data.

Parameters

data (relay.Expr) – The input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.squeeze(data, axis=None)

Squeeze axes in the array.

Parameters
  • data (tvm.relay.Expr) – The input data to the operator.

  • axis (None or List[int]) – The set of axes to remove. If axis = None, remove all axis of dimensions 1. If any specified axis has dimension that does not equal 1, it is an error.

Returns

result – The squeezed result.

Return type

tvm.relay.Expr

tvm.relay.op.stack(data, axis)

Join a sequence of arrays along a new axis.

Parameters
  • data (Union(List[relay.Expr], Tuple(relay.Expr))) – A list of tensors.

  • axis (int) – The axis in the result array along which the input arrays are stacked.

Returns

ret – The stacked tensor.

Return type

relay.Expr

tvm.relay.op.std(data, axis=None, keepdims=False, exclude=False)

Computes the standard deviation of data over given axes.

Parameters
  • data (relay.Expr) – The input data

  • axis (None or int or tuple of int) – Axis or axes along which a standard deviation operation is performed. The default, axis=None, will compute the standard deviation of all elements in the input array. If axis is negative it counts from the last to the first axis.

  • keepdims (bool) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.

  • exclude (bool) – If exclude is true, reduction will be performed on the axes that are NOT in axis instead.

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.strided_set(data, v, begin, end, strides=None)

Strided set of an array.

Parameters
  • data (relay.Expr) – The source array to be sliced.

  • v (relay.Expr) – The data to be set.

  • begin (relay.Expr) – The indices to begin with in the slicing.

  • end (relay.Expr) – Indices indicating end of the slice.

  • strides (relay.Expr, optional) – Specifies the stride values, it can be negative in that case, the input tensor will be reversed in that particular axis.

Returns

ret – The computed result.

Return type

relay.Expr

tvm.relay.op.strided_slice(data, begin, end, strides=None)

Strided slice of an array.

Parameters
  • data (relay.Expr) – The source array to be sliced.

  • begin (list of int) – The indices to begin with in the slicing.

  • end (list of int) – Indices indicating end of the slice.

  • strides (list of int, optional) – Specifies the stride values, it can be negative in that case, the input tensor will be reversed in that particular axis.

Returns

ret – The computed result.

Return type

relay.Expr

tvm.relay.op.subtract(lhs, rhs)

Subtraction with numpy-style broadcasting.

Parameters
  • lhs (relay.Expr) – The left hand side input data

  • rhs (relay.Expr) – The right hand side input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.sum(data, axis=None, keepdims=False, exclude=False)

Computes the sum of array elements over given axes.

Parameters
  • data (relay.Expr) – The input data

  • axis (None or int or tuple of int) – Axis or axes along which a sum is performed. The default, axis=None, will sum all of the elements of the input array. If axis is negative it counts from the last to the first axis.

  • keepdims (bool) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.

  • exclude (bool) – If exclude is true, reduction will be performed on the axes that are NOT in axis instead.

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.take(data, indices, axis=None, mode='clip')

Take elements from an array along an axis.

Parameters
  • data (relay.Expr) – The source array.

  • indices (rely.Expr) – The indices of the values to extract.

  • axis (int, optional) – The axis over which to select values. By default, the flattened input array is used.

  • mode (str, optional) – Specifies how out-of-bound indices will behave [clip, wrap, fast]. clip: clip to the range (default). wrap: wrap around the indices. fast: no clip or wrap around (user must make sure indices are in-bound).

Returns

ret – The computed result.

Return type

relay.Expr

tvm.relay.op.tan(data)

Compute elementwise tan of data.

Parameters

data (relay.Expr) – The input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.tanh(data)

Compute element-wise tanh of data.

Parameters

data (relay.Expr) – The input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.tile(data, reps)

Repeats the whole array multiple times.

Parameters
  • data (relay.Expr) – The input data to the operator.

  • reps (tuple of int) – The number of times repeating the tensor data.

Returns

ret – The computed result.

Return type

relay.Expr

Examples

x = [[1, 2], [3, 4]]
relay.tile(x, reps=(2,3)) = [[1., 2., 1., 2., 1., 2.],
                             [3., 4., 3., 4., 3., 4.],
                             [1., 2., 1., 2., 1., 2.],
                             [3., 4., 3., 4., 3., 4.]]

relay.tile(x, reps=(2,)) = [[1., 2., 1., 2.],
                            [3., 4., 3., 4.]]

Notes

Each dim size of reps must be a positive integer. If reps has length d, the result will have dimension of max(d, data.ndim); If data.ndim < d, data is promoted to be d-dimensional by prepending new axes. If data.ndim >= d, reps is promoted to a.ndim by pre-pending 1’s to it.

tvm.relay.op.topk(data, k=1, axis=-1, ret_type='both', is_ascend=False, dtype='int32')

Get the top k elements in an input tensor along the given axis.

ret_type specifies the return type, can be one of (“both”, “values”, “indices”).

Parameters
  • data (relay.Expr) – The input data tensor.

  • k (int, optional) – Number of top elements to select. Return all elements if k < 1.

  • axis (int, optional) – Axis long which to sort the input tensor.

  • ret_type (str, optional) – The return type [both, values, indices]. “both”: return both top k data and indices. “values”: return top k data only. “indices”: return top k indices only.

  • is_ascend (boolean, optional) – Whether to sort in ascending or descending order.

  • dtype (string, optional) – The data type of the indices output.

Returns

out – The computed result.

Return type

relay.Expr or List[relay.Expr]

tvm.relay.op.transpose(data, axes=None)

Permutes the dimensions of an array.

Parameters
  • data (relay.Expr) – The input data to the operator.

  • axes (None or List[int]) – The target axes order, reverse order if not specified.

Returns

result – The transposed result.

Return type

relay.Expr

tvm.relay.op.trunc(data)

Compute element-wise trunc of data.

Parameters

data (relay.Expr) – The input data

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.unravel_index(indices, shape)

Convert a flat index or array of flat indices into a tuple of coordinate arrays.

Example:: - unravel_index([22, 41, 37], [7, 6]) = [[3, 6, 6],[4, 5, 1]]

Parameters
  • indices (relay.Expr) – An integer array containing indices.

  • shape (relay.Expr) – The shape of the array.

Returns

result – The tuple of coordinate arrays.

Return type

relay.Expr

tvm.relay.op.variance(data, axis=None, keepdims=False, exclude=False)

Computes the variance of data over given axes.

Parameters
  • data (relay.Expr) – The input data

  • axis (None or int or tuple of int) – Axis or axes along which a variance operation is performed. The default, axis=None, will compute the variance of all elements in the input array. If axis is negative it counts from the last to the first axis.

  • keepdims (bool) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.

  • exclude (bool) – If exclude is true, reduction will be performed on the axes that are NOT in axis instead.

Returns

result – The computed result.

Return type

relay.Expr

tvm.relay.op.where(condition, x, y)

Selecting elements from either x or y depending on the value of the condition.

Note

The shape of condition, x, and y needs to be the same.

Parameters
  • condition (relay.Expr) – The condition array. The n-th element in y is selected when the n-th value in the condition array is zero. Otherwise, the corresponding element from x will be picked.

  • x (relay.Expr) – The first array to be selected.

  • y (relay.Expr) – The second array to be selected.

Returns

result – The selected array.

Return type

relay.Expr

Examples

x = [[1, 2], [3, 4]]
y = [[5, 6], [7, 8]]
condition = [[0, 1], [-1, 0]]
relay.where(conditon, x, y) = [[5, 2], [3, 8]]

condition = [1, 0]
relay.where(conditon, x, y) = [[1, 2], [7, 8]]
tvm.relay.op.zeros(shape, dtype)

Fill array with zeros.

Parameters
  • shape (tuple of int) – The shape of the target.

  • dtype (data type) – The data type of the target.

Returns

result – The resulting tensor.

Return type

relay.Expr

tvm.relay.op.zeros_like(data)

Returns an array of zeros, with same type and shape as the input.

Parameters

data (relay.Expr) – The input data

Returns

result – The computed result.

Return type

relay.Expr