Session Shape and Index Operations #
This file contains the session-level operations that preserve or rearrange tensor shape: activation helpers, reshapes, indexing, gathers, broadcasts, and reductions. Each operation dispatches through the same eager/typed graph session boundary as the lower-level tensor ops.
Rectified Linear Unit (ReLU) activation.
This is the pointwise nonlinearity $\operatorname{ReLU}(x)=\max(x,0)$, recorded as part of the session’s autograd graph.
PyTorch analogy: torch.relu(x) / torch.nn.functional.relu(x).
Instances For
Sigmoid (logistic) activation, applied pointwise.
PyTorch analogy: torch.sigmoid(x).
Instances For
Hyperbolic tangent activation, applied pointwise.
PyTorch analogy: torch.tanh(x).
Instances For
Softmax along an explicitly selected tensor dimension.
Instances For
Stable log-softmax along an explicitly selected tensor dimension.
Instances For
Softplus activation, applied pointwise: $\operatorname{softplus}(x)=\log(1+\exp x)$.
PyTorch analogy: torch.nn.functional.softplus(x).
Instances For
Elementwise exponential.
PyTorch analogy: torch.exp(x).
Instances For
Elementwise sine of angles in radians, using the session's eager or typed graph execution.
Instances For
Elementwise cosine, with gradients multiplied by -sin(x) on either execution path.
Instances For
Elementwise natural logarithm.
PyTorch analogy: torch.log(x).
If you need a total (always-defined) "log-like" surrogate without positivity side conditions, see
safeLog.
Instances For
Elementwise safe-log surrogate: $\operatorname{safeLog}(x;\varepsilon)=\log(\operatorname{softplus}(x)+\varepsilon)$.
We use this when we want something log-like but would rather not carry side conditions about inputs being strictly positive.
PyTorch analogy: torch.log(torch.nn.functional.softplus(x) + eps).
Instances For
Sum-reduce all elements of a tensor to a scalar.
PyTorch analogy: x.sum() (with no dim argument).
Instances For
Flatten a tensor to a 1D vector of length Spec.Shape.size sh.
PyTorch analogy: torch.flatten(x) or x.reshape(-1).
Instances For
Reshape a tensor without changing the number of elements.
The proof h : Spec.Shape.size sh1 = Spec.Shape.size sh2 plays the role of PyTorch’s runtime check
performed by reshape/view.
PyTorch analogy: x.reshape(new_shape) (when the element count matches).
Instances For
Generic "swap adjacent axes" view operation.
This is a shape-driven permutation helper used in some attention/transformer code.
Instances For
Broadcast a tensor to a larger shape (dispatches by execution mode).
Instances For
Reduce-sum along an axis (dispatches by execution mode).
Instances For
Reduce-mean along an axis (dispatches by execution mode).
Instances For
Select one bounded coordinate from an arbitrary tensor axis.
Instances For
Select several bounded coordinates from an arbitrary tensor axis.
Instances For
Add source slices into an arbitrary tensor axis at bounded coordinates.