ncl
Niao Column Library
Columnar data like pandas: typed columns, DataFrames, groupby, merges, and CSV I/O. Kernels are vectorized in Rust.
- Series & DataFrame
- Vectorized ops
- groupby & merge
- SQLite bridge
Niao Machine Learning
ML & Data
nml is the ML stack for Niao. You work with tensors, build models, and run training loops from Niao syntax, but the actual number crunching happens in Rust. CPU kernels use SIMD; if you have an NVIDIA GPU and CUDA installed, large matmuls can go there instead.
It covers the basics you'd expect (linear models, k-means, decision trees) plus graph layers like GCN and GraphSAGE. No Python runtime required; checkpoints and loss curves integrate with nvis if you want plots.
Import
import "nml" |
Quick start
import "nml" |
|
let x = nml.tensor([[1.0, 2.0], [3.0, 4.0]]) |
let w = nml.randn([2, 1]) |
let y = nml.matmul(x, w) |
print(y.shape()) |
High-level overview of what nml is for.
N-dimensional arrays with shape and dtype. Turn on autograd and the runtime builds a graph so backprop gives you gradients for training.
A training loop that handles epochs, batches, and loss logging. Save and reload model weights to disk between runs.
k-means, decision trees, random forests, and linear models for tabular data, useful when you don't need a full neural net.
GCN and GraphSAGE layers for node classification and link prediction on graph-shaped data.
Vectorized CPU paths by default. Optional CUDA path for big matrix work on supported GPUs.
50 functions and methods in nml. Grouped by category from the standard library docs.
| Signature | Description |
|---|---|
| nml_graph_from_dsa(g) | DSA graph → sparse adjacency handle |
| nml_graph_normalize(adj) | Symmetric normalized adjacency \(D^{-1/2} A D^{-1/2}\) |
| nml_gcn_layer(in, out) | GCN layer handle |
| nml_graphsage_layer(in, out) | GraphSAGE layer handle |
| nml_graph_forward(layer, features, adj) | One GNN layer forward pass |
| nml_graph_embed(adj, dim) | Structural embedding (random-walk lite) |
| nml_node_features_from_ncl(df, id_col, feat_cols) | Tabular features aligned to graph node ids |
| Signature | Description |
|---|---|
| nml_set_device(device) | Set compute device - cpu (default) or cuda:N |
| nml_device_count() | Number of CUDA devices (0 if unavailable) |
| Signature | Description |
|---|---|
| nml_randn(shape) | Random normal tensor |
| nml_zeros(shape) | Zero-filled tensor |
| nml_matmul(a, b) | Matrix multiply |
| nml_shape(tensor) | Tensor shape |
| nml_to_float_array(tensor) | Export tensor to FloatArray |
| nml_from_ncl(ndarray) | Bridge from NCL ndarray |
| Signature | Description |
|---|---|
| nml_linear(in, out) | Fully connected layer |
| nml_relu_layer() | ReLU activation layer |
| nml_conv2d_layer(...) | 2D convolution layer |
| nml_batch_norm2d(...) | Batch normalization layer |
| nml_sequential(layers) | Stack layers into a model |
| nml_forward(model, x) | Forward pass |
| Signature | Description |
|---|---|
| nml_trainer(model, optimizer, loss, lr) | Create training loop handle |
| nml_train_epoch(trainer, x, y) | Run one training epoch in Rust |
| nml_eval(trainer, x, y) | Evaluate loss on a dataset |
| nml_save(model, path) | Save model checkpoint |
| nml_load(path) | Load model checkpoint |
| nml_grid_search(...) | Hyperparameter grid search |
| nml_random_search(...) | Random hyperparameter search |
| nml_early_stopping(...) | Early stopping helper |
| Signature | Description |
|---|---|
| nml_enable_grad(tensor) | Track gradients for tensor |
| nml_zero_grad(model) | Reset parameter gradients |
| nml_backward(loss) | Backpropagate from loss |
| nml_parameters(model) | List trainable parameters |
| nml_backward_step(trainer) | Optimizer step after backward |
| Signature | Description |
|---|---|
| nml_from_dataframe(df, ...) | Build training tensors from NCL DataFrame |
| nml_train_test_split(data, ratio) | Split dataset for train/val |
| nml_normalize(data) | Min-max normalization |
| nml_standardize(data) | Z-score standardization |
| nml_one_hot(labels, n) | One-hot encode labels |
| nml_batch(data, size) | Batch iterator for training |
| nml_pipeline(steps) | Composable preprocessing DAG |
| nml_columnar_epoch(pipeline, ...) | Columnar epoch loader |
| Signature | Description |
|---|---|
| nml_kmeans(data, n, dims, k) | Fit k-means clustering |
| nml_kmeans_predict(km, data, n, dims) | Predict cluster labels |
| nml_logistic_fit(x, y, n, dims, epochs) | Logistic regression training |
| nml_decision_tree(x, y, n, dims, max_depth) | Train decision tree |
| nml_random_forest(x, y, n, dims, n_trees, max_depth) | Train random forest |
| Signature | Description |
|---|---|
| nml_memory_budget(bytes) | Set memory budget for training |
| nml_explain(model, x) | Model explanation helper |
| nml_plot_training(history) | Plot training loss history |
More from ML & Data.
Niao Column Library
Columnar data like pandas: typed columns, DataFrames, groupby, merges, and CSV I/O. Kernels are vectorized in Rust.
Niao Visualization
Charts for training runs and quick data checks. Save SVG or print ASCII in the terminal, no browser needed.