fn

cross

Tensor
cross(x: Tensor, y: Tensor, dim: int = -1)
source

Compute the cross product of two 3-D vectors.

Returns the standard 3-D vector cross product

x×y=(x2y3x3y2,  x3y1x1y3,  x1y2x2y1).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

xTensor
First operand. Must have size 3 along dim.
yTensor
Second operand. Same shape as x.
dimint= -1
Axis along which the 3 components are stored. Default -1.

Returns

Tensor

Cross product, same shape as inputs.

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 xysinθ\|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.0000, 0.0000, 1.0000])