{"id":30620304,"url":"https://github.com/BhavyeMathur/redstone-ml","last_synced_at":"2025-08-30T13:10:34.381Z","repository":{"id":268044768,"uuid":"900967335","full_name":"BhavyeMathur/redstone-ml","owner":"BhavyeMathur","description":"High-performance Machine Learning, Dynamic Auto-Differentiation and Tensor Algebra crate for Rust","archived":false,"fork":false,"pushed_at":"2025-06-08T16:15:31.000Z","size":2164,"stargazers_count":18,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-29T22:03:52.358Z","etag":null,"topics":["autograd-engine","linear-algebra","machine-learning","numpy","pytorch","tensor"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/chela","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BhavyeMathur.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-12-09T19:53:12.000Z","updated_at":"2025-06-16T08:04:12.000Z","dependencies_parsed_at":"2024-12-14T02:25:38.345Z","dependency_job_id":"31d98726-aa35-4f37-96fe-3dcb499eae6c","html_url":"https://github.com/BhavyeMathur/redstone-ml","commit_stats":null,"previous_names":["bhavyemathur/chela","bhavyemathur/redstone-ml"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/BhavyeMathur/redstone-ml","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BhavyeMathur%2Fredstone-ml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BhavyeMathur%2Fredstone-ml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BhavyeMathur%2Fredstone-ml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BhavyeMathur%2Fredstone-ml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BhavyeMathur","download_url":"https://codeload.github.com/BhavyeMathur/redstone-ml/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BhavyeMathur%2Fredstone-ml/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272853122,"owners_count":25004203,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-30T02:00:09.474Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autograd-engine","linear-algebra","machine-learning","numpy","pytorch","tensor"],"created_at":"2025-08-30T13:10:25.726Z","updated_at":"2025-08-30T13:10:34.373Z","avatar_url":"https://github.com/BhavyeMathur.png","language":"Rust","funding_links":[],"categories":["Machine Learning"],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\u003cimg src=\"https://github.com/BhavyeMathur/redstone-ml/blob/master/assets/logo/redstone-ml-red-logo.png\"/\u003e\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n![Crates.io Version](https://img.shields.io/crates/v/redstone-ml?color=%23ff5757)\n[![Test Status](https://github.com/BhavyeMathur/redstone-ml/actions/workflows/rust.yml/badge.svg)](https://github.com/BhavyeMathur/redstone-ml/actions/workflows/rust.yml)\n![license](https://shields.io/badge/license-MIT%2FApache--2.0-blue)\n\n---\n\n**High-performance Tensor Computation and Machine Learning\n\u003cbr/\u003e\nwith Dynamic Auto-Differentiation natively in Rust**\n\n\u003c/div\u003e\n\n---\n\nModeled after PyTorch and NumPy, it provides the following features:\n\n1. [N-dimensional Arrays](#n-dimensional-array-for-tensor-computations) (`NdArray`) for tensor computations.\n2. [Linear Algebra \u0026 Operations](#linear-algebra-broadcasting-and-reductions) with GPU and CPU acceleration\n3. [Dynamic Automatic Differentiation](#automatic-differentiation-with-redstone) (reverse-mode autograd) for machine learning.\n \nTo install either do `cargo install redstone-ml` or add this library to `Cargo.toml`.\n\nInternally, Redstone speeds up its operations using custom ARM NEON kernels, BLAS, and vDSP on supported architectures. This makes it blazing fast! The benchmark below is for single-threaded Apple Silicon.\n\n![https://github.com/BhavyeMathur/redstone-ml/blob/master/assets/tensor_operations.png](https://github.com/BhavyeMathur/redstone-ml/blob/master/assets/tensor_operations.png)\n\nThis project is still in its early stage, so feature requests, bugs, and other contributions are very welcome. Please contact me if you are interested!\n\n# Documentation\n\nMore detailed documentation is available [here]().\n\n# N-dimensional Array for Tensor Computations\n\nAn `NdArray` is a fixed-size multidimensional array container defined by its `shape`\nand datatype. 1D (vectors) and 2D (matrices) arrays are often of special interest\nand can be used in various linear algebra computations\nincluding dot products, matrix products, batch matrix multiplications, einsums, and more.\n\n`NdArrays` can be iterated over (along configurable dimensions), reshaped, sliced, and indexed,\nreduced, and more.\n\nThis struct is heavily modeled after NumPy's `ndarray` and supports many of the same methods.\n\nExample:\n\n```rust\nuse redstone_ml::*;\n\nlet matrix_a = NdArray::new([[1, 3, 2], [-1, 0, -1]]); // shape [2, 3]\nlet matrix_b = NdArray::randint([3, 7], -5, 3);\n\nlet matrix_view = matrix_b.slice_along(Axis(1), 0..2); // shape [3, 2]\nlet matrix_c = matrix_a.matmul(matrix_view);\n\nlet result = matrix_c.sum();\n```\n\n## NdArray Views \u0026 Lifetimes\n\nThere are 2 ways we can create NdArray views: by borrowing or by consuming:\n```rust\nlet data = NdArray::\u003cf64\u003e::rand([9]);\nlet matrix = (\u0026data).reshape([3, 3]); // by borrowing (data remains alive after)\n\nlet data = NdArray::\u003cf64\u003e::rand([9]);\nlet matrix = data.reshape([3, 3]); // by consuming data\n```\n\nThe consuming syntax allows us to chain operations without worrying about lifetimes\n```rust\n// a reshaped and transposed random matrix\nlet matrix = NdArray::\u003cf64\u003e::rand([9]).reshape([3, 3]).T();\n```\n\nOperations like `reshape`, `view`, `diagonal`, `squeeze`, `unsqueeze`, `T`, `transpose`, and\n`ravel` do not create new NdArrays by duplicating memory (which would be slow).\nThey always return `NdArray` views which share memory with the source `NdArray`.\n`NdArray::clone()` or `NdArray::flatten()` can be used to duplicate the underlying `NdArray`.\n\nThis means that all `NdArray` views have a lifetime at-most as long as the source `NdArray`.\n\n## Linear Algebra, Broadcasting, and Reductions\n\nWe currently support the core linear algebra operations including dot products,\nmatrix-vector and matrix-matrix multiplications, batched matrix multiplications, and trace.\n\n```rust\nvector1.dot(vector2);\n\nmatrix.trace(); // also trace_along/offset_trace\nmatrix.diagonal(); // also diagonal_along/offset_diagonal\nmatrix.matmul(vector);\nmatrix1.matmul(matrix2);\n\nbatch_matrices1.bmm(batch_matrices2);\n\n// generic einsums\neinsum([\u0026matrix1, \u0026matrix2, \u0026vector], ([\"ij\", \"kj\", \"i\"], \"ik\"));\n```\n\nWe can also perform various reductions including `sum`, `product`, `min`, `max`,\n`min_magnitude`, and `max_magnitude`. Each of these is accelerated with various libraries\nincluding vDSP, Arm64 NEON SIMD, and BLAS.\n\n```rust\nlet sum = ndarray.sum();\nlet sum_along = ndarray.sum_along([0, -1]); // sum along first and last axes\n```\n\n`NdArrays` can be used in arithmetic operations using the usual binary operators including\naddition (`+`), subtraction (`-`), multiplication (`*`), division (`/`), remainder (`%`),\nand bitwise operations (`\u0026`, `|`, `\u003c\u003c`, `\u003e\u003e`).\n\n```rust\nlet result = \u0026arr1 + \u0026arr2; // non-consuming\nlet result = \u0026arr1 + arr2;  // consumes RHS\nlet result = arr1 + arr2;   // consumes both\n```\n\n`NdArrays` are automatically broadcast using the exact same rules as NumPy\nto perform efficient computations with different-dimensional (yet compatible) data.\n\n## Slicing, Indexing, and Iterating\n\nSlicing and indexing an `NdArray` always return a view. This is how we can access various\nelements of vectors, columns/rows of matrices, and more.\n\n```rust\nlet arr = NdArray::\u003cf32\u003e::rand([2, 4, 3, 5]); // 4D NdArray\nlet slice1 = arr.slice(s![.., 0, ..=2]);      // use s! to specify a slice\nlet slice2 = arr.slice_along(Axis(-2), 0);    // 0th element along second-to-last axis\nlet el = arr[[0, 3, 2, 4]];\n```\n\nOne can also iterate over an `NdArray` in various ways:\n```rust\nfor subarray in arr.iter() { /* 4x3x5 subarrays */ }\nfor subarray in arr.iter_along(Axis(2)) { /* 2x4x5 subarrays */ }\nfor el in arr.flatiter() { /* element-wise iteration */ }\n```\n\n## Automatic Differentiation with Redstone\n\nThe `Tensor` API is nearly identical to `NdArray` with the following differences:\n1. Only floating point (`f32`, `f64`) types are supported\n2. Operations without autograd implemented are omitted\n\n`Tensors` allow us to perform dynamic automatic differentiation which is independent of control flow. This allows us to find matrix derivatives in complicated scenarios:\n\n```rust\nfn main() {\n    let mut a = Tensor::new([[7.5, 12.0], [5.0, 6.25]]);\n    let mut b = Tensor::new([0.5, -2.0]);\n    let c = Tensor::scalar(10.0);\n    \n    a.set_requires_grad(true); \n    b.set_requires_grad(true);\n    \n    let matrix_2x2 = (\u0026a / \u0026b) * (c + 5.0);\n    let result = matrix_2x2.matmul(\u0026b);\n    result.backward();\n\n    println!(\"{:?}\", a.gradient().unwrap());\n    println!(\"{:?}\", b.gradient().unwrap());\n}\n```\n\nGradients are only computed for `Tensors` with `requires_grad = true` to avoid unnecessary computation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBhavyeMathur%2Fredstone-ml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FBhavyeMathur%2Fredstone-ml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBhavyeMathur%2Fredstone-ml/lists"}