arange(start: _float, end: _float | None = None, step: _float = 1, dtype: DTypeLike = None, device: DeviceLike = None)Implementing kernel
C++ engine symbols that back this Python API.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
startint or floatend is
None, this argument is treated as end and start is
set to 0.endint or floatstepint or floatstart > end. Default: 1.dtypelucid.dtypeNone, inferred from
start, end and step: when every one of them is an
integer the result is int64, and a single float among them
makes it the global default float dtype (get_default_dtype).
A bool, another library's integer scalar and a
single-element integer tensor all count as integers. An explicit
dtype always wins.devicestr or lucid.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).
An int64 result is exact at any magnitude. The engine computes
each element in double precision, which holds integers exactly only
up to , so a range reaching past that is built from Python
integers instead.
Examples
>>> import lucid
>>> x = lucid.arange(5)
>>> x.tolist(), x.dtype
([0, 1, 2, 3, 4], lucid.int64)
One float argument makes the result floating point:
>>> y = lucid.arange(1.0, 2.0, 0.25)
>>> y.tolist(), y.dtype
([1.0, 1.25, 1.5, 1.75], lucid.float32)
Descending sequence:
>>> lucid.arange(5, 0, -1).tolist()
[5, 4, 3, 2, 1]
An explicit dtype overrides the rule, as for position encoding
indices that are wanted as floats:
>>> lucid.arange(4, dtype=lucid.float32).tolist()
[0.0, 1.0, 2.0, 3.0]
Integers past $2^{53}$ stay exact:
>>> lucid.arange(2**53 + 1, 2**53 + 3).tolist()
[9007199254740993, 9007199254740994]