Composable defn numerical kernels operating on raw Nx tensors.
This is the computational core of the math layer. The struct wrappers
(BB.Math.Vec3, BB.Math.Quaternion, BB.Math.Transform) delegate their
hot operations here, and higher-level algorithms (forward kinematics,
Jacobians, IK iterations) are expected to compose these kernels inside their
own defn rather than threading values back through eager per-op struct
calls.
Keeping the maths in defn is the point: a defn can be JIT-compiled,
vectorised over a leading batch axis, and composed into a larger computation,
none of which is possible for eager Nx.* calls dispatched one operation at
a time.
All inputs and outputs are raw :f64 tensors with these conventions:
- quaternions are
{4}tensors in WXYZ (scalar-first) order - transforms are
{4, 4}homogeneous matrices
Summary
Functions
Normalise a {4} quaternion tensor to unit length.
Hamilton product of two quaternions, returning a normalised unit quaternion.
Compose two {4, 4} homogeneous transforms.
Functions
Normalise a {4} quaternion tensor to unit length.
Falls back to the identity quaternion when the input is near-zero, so the result is always a valid unit rotation.
Hamilton product of two quaternions, returning a normalised unit quaternion.
quaternion_multiply(q1, q2) composes the rotations: q2 is applied first,
then q1. Inputs and output are {4} WXYZ tensors.
Compose two {4, 4} homogeneous transforms.
transform_compose(a, b) returns the transform that applies a first, then
b.