fn

arange

Tensor
arange(start: _float, end: _float | None = None, step: _float = 1, dtype: DTypeLike = None, device: DeviceLike = None)
source

Return a 1-D tensor of evenly spaced values over a half-open interval.

Generates the arithmetic sequence

xk=start+kstep,k=0,1,,N1x_k = \texttt{start} + k \cdot \texttt{step}, \quad k = 0, 1, \ldots, N-1

where N=endstartstepN = \left\lfloor \dfrac{\texttt{end} - \texttt{start}}{\texttt{step}} \right\rfloor is the number of elements. The interval is half-open: start is included, end is excluded, mirroring Python's built-in range.

When called with a single positional argument arange(n), the call is reinterpreted as arange(0, n, 1), yielding [0,1,,n1][0, 1, \ldots, n-1].

Parameters

startfloat
Starting value of the sequence (inclusive). When end is None, this argument is treated as end and start is set to 0.
endfloat
End of the interval (exclusive). Required unless using the single-argument form.
stepfloat
Spacing between consecutive values. May be negative (producing a decreasing sequence) provided start > end. Default: 1.
dtypelucid.dtype
Scalar data type of the output. If None, inferred from the types of start, end, and step: integer arguments yield int64; any float argument yields the global float default.
devicestr or lucid.device
Target device — "cpu" or "metal".

Returns

Tensor

1-D tensor containing the arithmetic sequence.

Notes

Due to floating-point rounding, the number of elements may differ from the naively expected (endstart)/step\lceil (\texttt{end} - \texttt{start}) / \texttt{step} \rceil by ±1\pm 1. When exact element counts matter, prefer linspace which always produces exactly steps values.

The last element is always strictly less than end (for positive step) or strictly greater than end (for negative step).

Examples

>>> import lucid
>>> lucid.arange(5).tolist()
[0, 1, 2, 3, 4]
>>> lucid.arange(1.0, 2.0, 0.25).tolist()
[1.0, 1.25, 1.5, 1.75]
Descending sequence:
>>> lucid.arange(5, 0, -1).tolist()
[5, 4, 3, 2, 1]
Position encoding indices:
>>> pos = lucid.arange(512, dtype=lucid.float32)