fn
arange
→Tensorarange(start: _float, end: _float | None = None, step: _float = 1, dtype: DTypeLike = None, device: DeviceLike = None)Return a 1-D tensor of evenly spaced values over a half-open interval.
Generates the arithmetic sequence
where
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
.
Parameters
startfloatStarting value of the sequence (inclusive). When
end is
None, this argument is treated as end and start is
set to 0.endfloatEnd of the interval (exclusive). Required unless using the
single-argument form.
stepfloatSpacing between consecutive values. May be negative (producing
a decreasing sequence) provided
start > end. Default: 1.dtypelucid.dtypeScalar 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.deviceTarget device —
"cpu" or "metal".Returns
Tensor1-D tensor containing the arithmetic sequence.
Notes
Due to floating-point rounding, the number of elements may differ
from the naively expected by . 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)