fn

atleast_1d

Tensor | tuple[Tensor, ...]
atleast_1d(tensors: Tensor = ())
source

Promote each input to at least 1 dimension.

Scalars (0-D tensors) are reshaped to length-1 vectors; tensors that already have rank 1\geq 1 pass through unchanged. Commonly used as a defensive guard at the top of routines that vectorise over a leading axis.

Parameters

*tensorsTensor
One or more input tensors of arbitrary rank.

Returns

Tensor | tuple[Tensor, ...]

A single tensor when called with one argument, otherwise a tuple of the promoted tensors in the same order as the inputs.

Notes

Promotion rule per input t with original rank r:

shape(t)={(1,),r=0,shape(t),r1.\text{shape}'(t) = \begin{cases} (1,), & r = 0, \\ \text{shape}(t), & r \geq 1. \end{cases}

Mirrors NumPy's np.atleast_1d. Higher-rank atleast_2d and atleast_3d variants follow the same pattern with extra leading / trailing unit axes.

Examples

>>> import lucid
>>> s = lucid.tensor(3.0)
>>> v = lucid.tensor([1.0, 2.0])
>>> a, b = lucid.atleast_1d(s, v)
>>> a.shape, b.shape
((1,), (2,))