The tensor module provides the core tensor types and operations for numerical computation.
Warning
Status: the operator surface below is the Core v1 spec surface — it type-checks and lowers through the IR, but not every operator listed is in the shipped native-execution subset yet. The proven, benchmarked native paths are the hand-lowered deterministic integer / Q16.16 fixed-point GEMM and FFT intrinsics. The strict f32 dot and matrix-vector fixtures also have exact matching AVX2/NEON output hashes; that evidence does not cover arbitrary floating-point reductions or every input (see RFC 0015 section 5A and the determinism docs).
Key Exports
Tensor<T, Shape>The primary tensor type with static shape
zeros, ones, fullTensor constructors
add, mul, matmulElement-wise and matrix operations
sum, mean, maxReduction operations
reshape, transpose, squeeze, expand_dimsShape manipulation
slice, gather, indexIndexing and selection
conv2d2D convolution with stride and padding control
fft, ifft, fft2dSpectral operations (FFT/IFFT)
Example Usage
use tensor::{Tensor, zeros, ones};
fn main() {
let a: Tensor<f32>[2, 3] = zeros();
let b: Tensor<f32>[2, 3] = ones();
let c = a + b; // Broadcasting add
print(c);
}Reduction Operations
Reductions accept keyword arguments for axis selection and dimension retention:
// Sum along axes with keyword arguments
let total = tensor.sum(x, axis=[1, 2], keepdims=true);
// Mean reduction
let avg = tensor.mean(activations, axis=[0]);
// Positional arguments also supported
let s = tensor.sum(x, [1, 2]);Shape Operations
// Reshape to new dimensions
let flat = tensor.reshape(x, [batch_size, 784]);
// Transpose with permutation
let t = tensor.transpose(x, perm=[0, 2, 1]);
// Add/remove dimensions
let expanded = tensor.expand_dims(x, axis=1);
let squeezed = tensor.squeeze(x, axis=[2]);Indexing and Slicing
// Slice with start:end:stride
let window = tensor.slice(x, [0, 0, 0], [batch, seq_len, dim]);
// Gather along axis
let selected = tensor.gather(embeddings, indices, axis=0);
// Convolution
let out = tensor.conv2d(input, filter, stride=[1, 1], padding="same");Spectral Operations
MIND provides first-class FFT primitives that compile to native code. All transforms run at O(N log N). Multi-vendor GPU backend dispatch (cuFFT, rocFFT, vDSP, WebGPU, WebNN) is planned on the commercial mind-runtime roadmap and is not yet shipped.
fft(signal)
1D Fast Fourier Transform. Real input [N] returns complex [N/2+1, 2]. Complex input [N, 2] returns complex [N, 2].
ifft(spectrum)
Inverse 1D FFT with automatic 1/N normalization. Round-trips ifft(fft(x)) back to x — bit-exact on the integer/fixed-point path, within float tolerance otherwise.
fft2d(signal)
2D FFT for image processing and spatial filtering. O(H * W * log(H * W)).
Planned Backend Dispatch
The following backend targets are planned for the commercial mind-runtime and are not yet available in the shipped compiler.
| Backend | Library |
|---|---|
| CUDA | cuFFT |
| ROCm | rocFFT |
| Metal | vDSP / Accelerate |
| WebGPU | WGSL Cooley-Tukey |
| WebNN | MLGraphBuilder ops (CPU/GPU/NPU) |
FFT Example: Low-Pass Filter
use tensor::{fft, ifft, zeros, ones};
fn low_pass_filter(signal: Tensor, cutoff: i64) -> Tensor {
let spectrum = fft(signal);
let n = spectrum.shape[0];
let mask = zeros([n, 2]);
for i in 0..cutoff {
mask[i] = ones([2]);
mask[n - 1 - i] = ones([2]);
}
return ifft(spectrum * mask);
}