Namespace for mathematical operations on tensors. Useful with MLComponent.

Tensor broadcasting rules*

Tensor (channels, width, height) op Tensor (1, 1, 1) = the same as applying op with scalar

Tensor (channels, width, height) op Tensor (channels, 1, 1) = the same as applying op per channel

// Convert a texture to an array of grayscale values
// @input Asset.Texture texture

// Desired width and height of the grayscale texture
// You can instead use Texture.getWidth() and Texture.getHeight() for original size
var width = 64;
var height = 64;

var data = new Uint8Array(height * width);
var shape = new vec3(width, height, 1);

// Get the texture pixels as grayscale values (0-255)
TensorMath.textureToGrayscale(script.texture, data, shape);