nml
Niao Machine Learning
Machine learning in Niao: tensors, training loops, classic algorithms, and graph models. Heavy math runs in Rust (SIMD on CPU, CUDA optional).
- Tensors & autograd
- Training loops
- k-means & trees
- GCN / GraphSAGE
Niao Column Library
ML & Data
ncl is for when your data is tables, not tensors. Columns are stored in packed typed arrays (int, float, string) and operations run across whole columns in one native pass, similar to pandas/numpy, but inside Niao.
Load a CSV, filter rows, group by a key and aggregate, join two frames, or push results into SQLite. If you're doing ML on tabular data, ncl gets the data ready and nml trains on it.
Import
import "ncl" |
Quick start
import "ncl" |
|
let df = ncl.read_csv("sales.csv") |
let summary = df.groupby("region").agg({ revenue: "sum", units: "mean" }) |
print(summary.head(5)) |
High-level overview of what ncl is for.
A DataFrame is a set of named columns with a shared row index. Select columns, filter, sort, and slice rows the way you'd expect from pandas.
Add two columns, compare values, run abs/sqrt/log across an entire column, one call, no Python-style row loops.
Split on a key column and aggregate (sum, mean, count, etc.). Join frames on shared keys with inner, left, or outer semantics.
Read and write CSV with configurable delimiters and headers. Type inference on load so numbers stay numbers.
Run a query through nsqlite and land the result directly in a DataFrame, or write a frame back to a table.
47 functions and methods in ncl. Grouped by category from the standard library docs.
| Signature | Description |
|---|---|
| ncl.zeros(n, as_float?) | Zero-filled packed array |
| ncl.ones(n, as_float?) | Ones-filled packed array |
| ncl.arange(start, stop, step?) | Integer range → `IntArray` |
| ncl.linspace(start, stop, n) | Evenly spaced floats → `FloatArray` |
| ncl.array(data) | Homogeneous array from Niao array literal |
| ncl.slice(arr, start, end) | Zero-copy-style slice (new buffer) |
| ncl.add(a, b) | Element-wise ops on packed arrays |
| ncl.sub(a, b) | Element-wise ops on packed arrays |
| ncl.mul(a, b) | Element-wise ops on packed arrays |
| ncl.div(a, b) | Element-wise ops on packed arrays |
| ncl.abs / sqrt / exp / log / sin / cos | Unary math ufuncs |
| ncl.sum / mean / min / max / std / var / median | Reductions |
| ncl.corr(a, b) | Pearson correlation |
| ncl.dot(a, b) | Dot product |
| ncl.parallel_sum(arr) | Rayon parallel sum (large arrays) |
| Signature | Description |
|---|---|
| ncl.series(data, name?) | 1D column from packed array |
| ncl.dataframe({col: array, …}) | Aligned multi-column table |
| ncl.df_get(df, name) | Column as Series |
| ncl.df_set(df, name, array) | Assign/replace column |
| ncl.df_columns(df) | Column name list |
| ncl.df_shape(df) | `[rows, cols]` |
| ncl.series_values(s) | Packed array backing |
| ncl.head(df, n?) | Row slice |
| ncl.tail(df, n?) | Row slice |
| ncl.filter(df, mask) | Boolean/int mask select |
| ncl.sort_values(df, col, desc?) | Sort by column |
| Signature | Description |
|---|---|
| ncl.groupby(df, key) | Split by int/string key column |
| ncl.agg(group, {col: "sum"\ | "mean"\ |
| ncl.merge(left, right, on) | Inner join on int key |
| ncl.concat(a, b) | Vertical stack |
| ncl.pivot(df, index, columns, values) | Pivot table |
| ncl.melt(df, id_vars) | Wide → long |
| Signature | Description |
|---|---|
| ncl.isna(series) | Null mask |
| ncl.fillna(series, value) | Fill nulls |
| ncl.dropna(series) | Remove null rows |
| ncl.rolling_mean(s, window) | Sliding mean |
| ncl.rolling_sum / rolling_std | Sliding sum / std |
| ncl.describe(series) | count, mean, std, min, max |
| Signature | Description |
|---|---|
| ncl.read_csv(path) | Typed CSV → DataFrame |
| ncl.to_csv(df, path?) | Write file or return string |
| ncl.from_sqlite(conn, sql, params?) | Packed columns from nsqlite |
| ncl.to_datetime(series, format?) | Parse string column to epoch ms |
| Signature | Description |
|---|---|
| ncl.ndarray(shape, data) | N-dimensional homogeneous array |
| ncl.shape(arr) | Shape ops |
| ncl.dtype(arr) | Shape ops |
| ncl.reshape(arr) | Shape ops |
| ncl.flatten(arr) | Shape ops |
More from ML & Data.
Niao Machine Learning
Machine learning in Niao: tensors, training loops, classic algorithms, and graph models. Heavy math runs in Rust (SIMD on CPU, CUDA optional).
Niao Visualization
Charts for training runs and quick data checks. Save SVG or print ASCII in the terminal, no browser needed.