colour.utilities.xp_reshape#

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

Array API compatible implementation of numpy.reshape().

This typed wrapper exists because xp is typed as Any, so xp.reshape(...) returns Any. When the result is assigned back to a variable that was originally a function parameter (e.g., a: ArrayLike), Pyright reverts the variable to its declared type instead of narrowing it. This wrapper declares -> NDArray so that Pyright can track the narrowed type through reassignments.

Callers must promote Python scalars / lists to the backend namespace beforehand (e.g. via xp_as_float_array()), since strict backends like PyTorch reject raw scalars and the wrapper cannot infer the target device for a scalar input.

Parameters:
Returns:

Reshaped array.

Return type:

object