fn

linspace

Tensor
linspace(start: _float, end: _float, steps: _int, dtype: DTypeLike = None, device: DeviceLike = None)
source

Return a 1-D tensor of steps equally spaced values over a closed interval.

Generates the arithmetic sequence

xk=start+kendstartsteps1,k=0,1,,steps1x_k = \texttt{start} + k \cdot \frac{\texttt{end} - \texttt{start}}{\texttt{steps} - 1}, \quad k = 0, 1, \ldots, \texttt{steps} - 1

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

startfloat
Starting value of the sequence (inclusive).
endfloat
Ending value of the sequence (inclusive).
stepsint
Number of evenly spaced samples. Must be 1\geq 1. When steps = 1 the output contains only start.
dtypelucid.dtype
Scalar data type. Defaults to the global default float dtype.
devicestr or lucid.device
Target device — "cpu" or "metal".

Returns

Tensor

1-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 Δ=(endstart)/(steps1)\Delta = (\texttt{end} - \texttt{start}) / (\texttt{steps} - 1), so the output satisfies xsteps1=endx_{\texttt{steps}-1} = \texttt{end} to within floating-point precision.

For frequency grids in signal processing the common pattern is:

fk=kNfs,k=0,,N1f_k = \frac{k}{N} \cdot f_s, \quad k = 0, \ldots, N-1

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]