Core Concepts / Tensor & AI Computing

Tensor & AI Computing

Aero's AI highlight: built-in 2D tensors and matrix multiplication, plus built-in automatic differentiation (Grad).

Basic Tensor Usage

let t = tensor(3, 4);     // 3 行 4 列的二维张量(零初始化)
t.set(0, 0, 1);           // 按索引读写
let v = t.get(1, 2);

Matrix Multiplication matmul

let a = tensor(2, 3);
let b = tensor(3, 4);
let c = matmul(a, b);     // 2x4,维度编译期校验(左列数 = 右行数)

Automatic Differentiation (Grad)

The standard library ships a reverse-mode (backprop) engine: an explicit tape records the op tree, and one backward pass yields gradients for all leaves:

let g = grad_new();                    // 新建图
let x = g_leaf(g, 2.0);                // 叶子
let y = g_leaf(g, 3.0);
let z = g_mul(g, x, y);                // z = x * y
g_backward(g, z);                      // 反向传播
print(g_grad(g, x));                   // 对 x 的梯度 = y = 3
print(g_grad(g, y));                   // 对 y 的梯度 = x = 2
grad_new()create a new tape
g_leaf(g, v)leaf node
g_add / g_mul / g_neg / g_inv / g_sub / g_divoperation nodes
g_backward(g, root)backward pass
g_grad(g, node)get the gradient
g_val(g, node)get the value

v1 boundaries: Tensor currently only has zero-init + matmul; operators like addition/transpose/dot product are not yet available (the GPU kernel interface has been left open).

Aero 文档 · 基于 Aero 1.2.0 文档整理 · MIT
SereinTeam