Skip to content
fn

cross

→Tensor
cross(input: Tensor, other: Tensor, dim: int = -1)

Compute the cross product of two 3-D vectors.

Returns the standard 3-D vector cross product

x×y = (x2y3−x3y2,  x3y1−x1y3,  x1y2−x2y1).x \times y \,=\, \big(x_2 y_3 - x_3 y_2,\; x_3 y_1 - x_1 y_3,\; x_1 y_2 - x_2 y_1\big).

Parameters

inputTensor
First operand. Must have size 3 along dim.
otherTensor
Second operand. Same shape as input.
dim(int, keyword - only)= -1
Axis along which the 3 components are stored. Default -1.

Returns

Tensor

Cross product, same shape as inputs.

Raises

DtypeMismatch
If input and other have different dtypes, as the reference does.
NotImplementedError
If both are bool tensors: the reference has no bool kernel. An integer pair is answered.

Notes

Implemented via gather + element-wise products so that autograd flows through naturally. Recall that x×yx \times y is orthogonal to both xx and yy, with magnitude ∥x∥ ∥y∥ sin⁡θ\|x\|\,\|y\|\,\sin\theta.

Examples

>>> import lucid
>>> from lucid.linalg import cross
>>> cross(lucid.tensor([1.0, 0.0, 0.0]), lucid.tensor([0.0, 1.0, 0.0]))
tensor([0., 0., 1.])

Used by 1