VTL is a pure-V tensor library for numerical computing and machine learning. It provides n-dimensional arrays with automatic differentiation, linear algebra via VSL, and a full neural network module.
- Tensor operations — create, slice, reshape, transpose, broadcast, map/reduce
- Autograd — reverse-mode automatic differentiation; build arbitrary computational graphs
- Neural networks —
Sequentialmodel API; layers (Linear, Conv2D, LSTM, Attention, …); losses (MSE, BCE, CrossEntropy, Huber, …); optimizers (Adam, AdamW, RMSProp, AdaGrad, SGD) - Linear algebra — VSL-backed: matmul, solve, lstsq, qr, lu, cholesky, pinv, trace, norm, SVD
- Hardware acceleration — zero-copy sharing with C libraries via
vtl.Tensor.data
import vtl
import vtl.autograd
import vtl.nn.layers
import vtl.nn.models
import vtl.nn.optimizers
// 1. Build a two-layer network using Sequential API
mut ctx := autograd.ctx[f64]()
mut model := models.sequential_from_ctx[f64](ctx)
model.input([784])
model.linear(256) // 784 -> 256
model.linear(10) // 256 -> 10
// 2. Forward pass
input_tensor := vtl.zeros[f64]([64, 784])
mut x := ctx.variable(input_tensor)
y_pred := model.forward(x)!
// 3. Loss
target := vtl.zeros[f64]([64, 10])
mut loss_val := model.loss(y_pred, target)!
// 4. Backward + update
loss_val.backprop()!
mut opt := optimizers.adam_optimizer[f64](optimizers.AdamOptimizerConfig{
learning_rate: 0.001
})
opt.build_params(model.info.layers)
opt.update()!| Module | Purpose |
|---|---|
vtl |
Core Tensor[T] type; creation, slicing, broadcasting |
vtl.autograd |
Context, Variable, gates, backprop() |
vtl.la |
Linear algebra (wraps VSL) |
vtl.nn |
Neural network layers, losses, optimizers |
vtl.nn.models |
Sequential model API |
vtl.nn.internal |
Weight initialisation (Kaiming, Xavier) |
vtl.nn.gates |
Autograd gate implementations |
VTL depends on VSL. Follow the VSL install instructions before installing VTL.
v install vtlv test ~/.vmodules/vtlAll tutorials live in docs/:
| Tutorial | Topic |
|---|---|
| TUTORIAL_FIRST_STEPS.md | Tensor creation, indexing, slicing |
| TUTORIAL_MAP_REDUCE.md | map / nmap and reductions |
| TUTORIAL_AUTOGRAD.md | Autograd: Variable, gates, backprop |
| TUTORIAL_REDUCTIONS.md | argmax / argmin / cumsum / cumprod |
| TUTORIAL_NEURAL_NETWORKS.md | Layers, losses, optimizers, Sequential |
| TUTORIAL_OPTIMIZERS.md | Adam / AdamW / RMSProp / AdaGrad / SGD + schedulers |
| TUTORIAL_LINEAR_ALGEBRA.md | LA basics via VSL |
| TUTORIAL_ADVANCED_LA.md | trace / norm / qr / lu / cholesky / pinv |
| TUTORIAL_BROADCASTING.md | Broadcasting rules |
| TUTORIAL_SLICING.md | Slicing and views |