# rorch **Repository Path**: MoleSir/rorch ## Basic Information - **Project Name**: rorch - **Description**: Pytorch-style Tensor+Autograd library written in Rust - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-06-12 - **Last Updated**: 2025-06-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: Tensor, Rust, Machine-learning ## README # Rorch Tensor library for machine learning (But in Rust). ## Usages Use `Tensor` like PyTroch: ````rust use rorch::prelude::*; let t = Tensor::from([[1, 2], [3, 4]]); let zt = t.zeros_like(); let t = Tensor::rand([5, 4]); let t = Tensor::build(vec![1., 2., 3., 4.], [2, 2]).unwrap(); let col_t = t.reshape([1, 4]).unwrap(); let row_t = t.reshape([4, 1]).unwrap(); ```` Build a network use `rorch::nn` just like PyTroch: ````rust use rorch::prelude::*; use rorch::data::{dataset::IrisDataSet, DataLoader}; use rorch::nn::{Criterion, Model, Optim}; let dataset = IrisDataSet::new(); let dataloader = DataLoader::new(dataset, 16, true); let model = nn::model::MLP::from_archs(vec![4, 10, 3]).unwrap(); let criterion = nn::criterion::MSELoss::new(); let mut optimizer = nn::optim::SDG::new(model.parameters(), 0.01); const EPOCHS: usize = 100; for epoch in 0..EPOCHS { for (i, (x, y)) in dataloader.iter().enumerate() { optimizer.zero_grad(); let pred = model.forward(&x).unwrap(); let loss = criterion.loss(&pred, &y).unwrap(); loss.backward(); optimizer.step(); if i == 0 && epoch % 10 == 0 { println!("Epoch: {epoch}/{EPOCHS}, Loss: {:?}", loss.mean()); } } } ```` ## Features - Auto grad `Tensor` - nn: - `MLP` - `Linear` - `RNN` - Dataset and dataloader - iris ## Examples In ./src/examples ### [Iris](./examples/iris) Use a simple MLP to train iris dataset. ### [Function Fitting](./examples/function_fitting) Use a simple RNN + Linear net to fit a given function(`fn(f64) -> f64`). There is an example for `cos`, the image show the predict curve after trainng: ![](./image/predict_cos.svg)