colour.utilities.xp_matrix_transpose#

colour.utilities.xp_matrix_transpose(a: ArrayLike, *, xp: ProtocolArrayNamespace | ModuleType | None = None) NDArray[source]#

Array API compatible implementation of numpy.matrix_transpose() materialising the result to a C-contiguous array.

Equivalent to xp.matrix_transpose(a) followed by xp_ascontiguousarray(). Use whenever the transposed array will participate in subsequent broadcasts or matmul operations; the lazy stride-permuted view returned by the standard matrix_transpose poisons broadcast outputs (the NumPy broadcast machinery inherits the strided layout into the freshly-allocated output) and forces BLAS to copy internally on every matmul. The cost of materialising once is amortised by keeping all downstream broadcasts and matmuls on contiguous memory.

Parameters:
Returns:

Matrix-transposed and C-contiguous array.

Return type:

object

Examples

>>> a = np.arange(6).reshape(2, 3)
>>> xp_matrix_transpose(a, xp=np)
array([[0, 3],
       [1, 4],
       [2, 5]])