fn
linspace
→Tensorlinspace(start: _float, end: _float, steps: _int, dtype: DTypeLike = None, device: DeviceLike = None)Return a 1-D tensor of steps equally spaced values over a closed interval.
Generates the arithmetic sequence
Unlike arange, the interval is closed on both ends: start
and end are both included in the output, and the number of
elements is always exactly steps.
Parameters
startfloatStarting value of the sequence (inclusive).
endfloatEnding value of the sequence (inclusive).
stepsintNumber of evenly spaced samples. Must be .
When
steps = 1 the output contains only start.dtypelucid.dtypeScalar data type. Defaults to the global default float dtype.
devicestr or lucid.deviceTarget device —
"cpu" or "metal".Returns
Tensor1-D tensor of shape (steps,) with evenly spaced values.
Notes
linspace is preferable to arange whenever:
- The exact number of points is prescribed (e.g. FFT grid, sinusoidal position encodings, Gaussian quadrature nodes).
- Floating-point rounding in the step size would cause off-by-one element counts.
The spacing between consecutive elements is exactly , so the output satisfies to within floating-point precision.
For frequency grids in signal processing the common pattern is:
which can be constructed as linspace(0, fs, N, endpoint=False)
(use arange(N) / N * fs for the half-open variant).
Examples
>>> import lucid
>>> lucid.linspace(0.0, 1.0, 5).tolist()
[0.0, 0.25, 0.5, 0.75, 1.0]
Sinusoidal position encoding grid:
>>> t = lucid.linspace(0.0, 2 * 3.14159, 64)
>>> t.shape
(64,)
Single-element edge case:
>>> lucid.linspace(3.0, 7.0, 1).tolist()
[3.0]