fn

logspace

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

Return a 1-D tensor of steps values evenly spaced on a logarithmic scale.

Generates the geometric sequence

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

Equivalently, the exponents yky_k are linearly spaced (as in linspace) and then the base is raised to those exponents. The result spans the range [basestart,baseend][\texttt{base}^\texttt{start},\, \texttt{base}^\texttt{end}] multiplicatively: consecutive elements satisfy xk+1/xk=constx_{k+1} / x_k = \text{const}.

Parameters

startfloat
Exponent of the first value. The first element equals basestart\texttt{base}^\texttt{start}.
endfloat
Exponent of the last value. The last element equals baseend\texttt{base}^\texttt{end}.
stepsint
Number of samples. Must be 1\geq 1.
basefloat
Logarithm base. Common choices:
  • 10.0 (default) — decades, used in frequency / magnitude plots
  • 2.0 — octaves, used in learning-rate schedules and wavelets
  • math.e (2.718\approx 2.718) — natural exponential spacing
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 geometrically spaced values.

Notes

Logarithmic spacing appears in:

  • Learning-rate grid search — scanning [105,101][10^{-5}, 10^{-1}] with logspace(-5, -1, 9) covers five decades uniformly in log-space rather than concentrating samples near the upper bound as linear spacing would.
  • Frequency analysis — the mel and bark scales approximate human auditory perception and are nearly logarithmic in Hz.
  • Sinusoidal position encodings (Vaswani et al., 2017) use ωk=100002k/d\omega_k = 10000^{-2k/d}, which is a logspace on base 1000010000.

The ratio between adjacent elements is constant:

xk+1xk=base(endstart)/(steps1)\frac{x_{k+1}}{x_k} = \texttt{base}^{\,(\texttt{end}-\texttt{start})\,/\,(\texttt{steps}-1)}

Examples

>>> import lucid
>>> lucid.logspace(0, 3, 4).tolist()
[1.0, 10.0, 100.0, 1000.0]
Two-octave learning-rate sweep (base 2):
>>> lrs = lucid.logspace(-8, -1, 8, base=2.0)
>>> lrs.tolist()
[0.00390625, 0.0078125, ..., 0.5]
Sinusoidal position encoding frequencies (Transformer convention):
>>> d_model = 512
>>> inv_freq = lucid.logspace(0, -1, d_model // 2, base=10000.0)