Skip to content
fn

one_hot_op

→TensorImplPtr
int one_hot_op(const int & input, int num_classes, Dtype out_dtype)

Python wrappers

Public Python APIs implemented by this engine symbol.

Encode integer indices into one-hot float vectors.

Returns a tensor of shape (*input.shape(), num_classes) where the last axis is the one-hot indicator

y…,c=1[c=input…],c∈{0,1,…,num_classes−1}. y_{\ldots, c} = \mathbf{1}\bigl[c = \text{input}_{\ldots}\bigr], \quad c \in \{0, 1, \ldots, \text{num\_classes} - 1\}.

The output dtype is out_dtype (typically a floating-point type so the result can feed directly into a loss function). Indices outside the [0,num_classes)[0, \text{num\_classes}) range produce all-zero rows. No autograd node is attached — this op is inference-only.

Parameters

inputTensorImplPtr
Integer tensor of arbitrary shape.
num_classesint
Length of the one-hot dimension.
out_dtypeDtype
Element type of the output (e.g. Dtype::Float32).

Returns

TensorImplPtr

One-hot tensor of shape (*input.shape(), num_classes) and dtype out_dtype.