Skip to content
fn

clip_op

→TensorImplPtr
int clip_op(const int & a, double min_v, double max_v)

Python wrappers

Public Python APIs implemented by this engine symbol.

Element-wise clamp — returns a clipped to the range [min_v, max_v] with a fully wired autograd node.

Math

yi=max⁡(min_v, min⁡(max_v, xi))y_i = \max\bigl(\text{min\_v},\ \min(\text{max\_v},\ x_i)\bigr)

Shape

Output shape equals input shape (elementwise).

See Also

ClipBackward.

Parameters

aTensorImplPtr
Input tensor (integer or floating-point).
min_vdouble
Lower clamp bound.
max_vdouble
Upper clamp bound (must satisfy min_v <= max_v).

Returns

TensorImplPtr

Clamped output tensor with the same shape, dtype, and device as a. Gradient is g where min_v < a < max_v and zero where a saturates either bound.

Notes

Equivalent to reference framework's clamp (Lucid uses the name clip for the canonical op). Saturated positions act as gradient stoppers — useful for hard-tanh-style activations.