{"id":29817036,"url":"https://github.com/reinterpretcat/zero-depend","last_synced_at":"2025-07-28T20:11:53.664Z","repository":{"id":305314420,"uuid":"1022326782","full_name":"reinterpretcat/zero-depend","owner":"reinterpretcat","description":"Educational Rust workspace featuring zero-dependency crates built using only standard library ","archived":false,"fork":false,"pushed_at":"2025-07-19T15:08:01.000Z","size":39,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-07-19T15:26:17.488Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/reinterpretcat.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":"2025-07-18T21:14:16.000Z","updated_at":"2025-07-19T15:08:05.000Z","dependencies_parsed_at":"2025-07-19T15:39:31.238Z","dependency_job_id":null,"html_url":"https://github.com/reinterpretcat/zero-depend","commit_stats":null,"previous_names":["reinterpretcat/zero-depend"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/reinterpretcat/zero-depend","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reinterpretcat%2Fzero-depend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reinterpretcat%2Fzero-depend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reinterpretcat%2Fzero-depend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reinterpretcat%2Fzero-depend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reinterpretcat","download_url":"https://codeload.github.com/reinterpretcat/zero-depend/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reinterpretcat%2Fzero-depend/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267578003,"owners_count":24110351,"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-07-28T02:00:09.689Z","response_time":68,"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":[],"created_at":"2025-07-28T20:11:52.393Z","updated_at":"2025-07-28T20:11:53.651Z","avatar_url":"https://github.com/reinterpretcat.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Zero Dependency Rust Workspace\n\nThis repository demonstrates a **zero dependency** philosophy: all crates are implemented using only the Rust standard library, with no external dependencies. The primary goal is educational—showcasing how to build robust, efficient, and idiomatic Rust libraries from scratch, without relying on third-party crates. While the code aims for high quality, it is primarily a learning project and may not always reach full production-grade standards.\n\nSome of the code in this workspace was generated or assisted by large language models (LLMs), exploring how AI can help design and implement foundational Rust libraries from scratch.\n\nCross-references between crates are allowed where appropriate (for example, `small-vec` is used as a building block in `tensor-rs`).\n\nThis approach helps:\n\n- Deepen understanding of Rust's core features and standard library\n- Encourage learning by re-implementing common abstractions\n- Improve portability and auditability (no supply chain risk)\n- Minimize compile times and binary size\n- Provide a clear reference for how things work \"under the hood\"\n\n## Crates in this Workspace\n\n* **tensor-rs**: A minimal, PyTorch-like tensor library. Demonstrates multi-dimensional array operations, views, and basic math.\n* **par-iter**: A parallel iterator library inspired by rayon. Implements parallel iteration and combinators (map, zip, enumerate, etc.) using only threads and atomics from the standard library.\n* **small-vec**: A small vector implementation. Provides a vector-like container optimized for small sizes, storing elements on stack when possible, and falling back to heap allocation for larger sizes.\n\nEach crate is a standalone Rust library, ready for further development or as a learning resource.\n\n\n## Examples\n\n### tensor-rs\n\n#### Basic Usage\n```rust\nuse tensor_rs::Tensor;\n\n// 1D tensor\nlet t = Tensor::\u003ci32\u003e::arange(5)?;\nassert_eq!(format!(\"{t}\"), \"[0, 1, 2, 3, 4]\");\n\n// 2D tensor\nlet t2 = Tensor::\u003ci32\u003e::arange(6)?.view(\u0026[2, 3])?;\nassert_eq!(format!(\"{t2}\"), \"[[0, 1, 2],\\n [3, 4, 5]]\");\n```\n\n#### Matrix Operations\n```rust\nuse tensor_rs::Tensor;\n\n// Matrix multiplication\nlet a = Tensor::\u003ci32\u003e::arange(6)?.view(\u0026[2, 3])?;\nlet b = Tensor::\u003ci32\u003e::arange(6)?.view(\u0026[3, 2])?;\nprintln!(\"{}\", a.matmul(\u0026b)?);\n//[[10, 13],\n// [28, 40]]\n\n// 2D x 2D batch matmul\nlet a = Tensor::\u003ci32\u003e::arange(12)?.view(\u0026[2, 3, 2])?;\nlet b = Tensor::\u003ci32\u003e::arange(6)?.view(\u0026[2, 3])?;\nprintln!(\"{}\", a.matmul(\u0026b)?);\n// [[[ 3,  4,  5],\n//   [ 9, 14, 19],\n//   [15, 24, 33]],\n\n//  [[21, 34, 47],\n//   [27, 44, 61],\n//   [33, 54, 75]]]\n\n```\n\n#### Slicing and Views\n```rust\n\n// Create a 4x6 test tensor for slicing examples\nlet tensor = Tensor::\u003ci32\u003e::arange(24)?.view(\u0026[4, 6])?;\n\n// 1. Full slice (returns the whole tensor)\nlet full_slice = tensor.slice(s![.., ..])?;\nassert_eq!(full_slice, tensor);\n\n// 2. Row slice (second row)\nlet row_slice = tensor.slice(s![1, ..])?;\nassert_eq!(row_slice, Tensor::from(vec![6, 7, 8, 9, 10, 11]));\n\n// 3. Column slice (third column)\nlet col_slice = tensor.slice(s![.., 2])?;\nassert_eq!(col_slice, Tensor::from(vec![2, 8, 14, 20]));\n\n// 4. Range slice (rows 1..3, cols 2..5)\nlet range_slice = tensor.slice(s![1..3, 2..5])?;\nassert_eq!(range_slice, Tensor::new(vec![8, 9, 10, 14, 15, 16], \u0026[2, 3])?);\n\n// 5. Negative single index (last row)\nlet last_row = tensor.slice(s![-1, ..])?;\nassert_eq!(last_row, Tensor::from(vec![18, 19, 20, 21, 22, 23]));\n\n// 6. Negative range (last two rows)\nlet last_two_rows = tensor.slice(s![-2.., ..])?;\nassert_eq!(last_two_rows, Tensor::try_from(vec![[12, 13, 14, 15, 16, 17], [18, 19, 20, 21, 22, 23]])?);\n\n// 7. Negative end (all but last column)\nlet without_last_col = tensor.slice(s![.., ..-1])?;\nassert_eq!(without_last_col.shape(), \u0026[4, 5]);\n\n// 8. Step by 2 on first dimension\nlet stepped = tensor.slice(\u0026[step![.., 2]])?;\nassert_eq!(stepped.shape(), \u0026[2, 6]);\n\n// 9. Step with range\nlet stepped_range = tensor.slice(\u0026[step![0..3, 2]])?;\nassert_eq!(stepped_range.shape(), \u0026[2, 6]);\n\n// 10. Inclusive range\nlet inclusive = tensor.slice(s![1..=2, 2..=4])?;\nassert_eq!(inclusive.shape(), \u0026[2, 3]);\n\n// 11. Empty slice\nlet empty = tensor.slice(s![1..1, ..])?;\nassert_eq!(empty.shape(), \u0026[0, 6]);\n\n// 12. Single element\nlet single = tensor.slice(s![1, 2])?;\nassert_eq!(single.shape(), \u0026[]);\nassert_eq!(single.elements().count(), 1);\n\n// 13. Macro-based slicing with negative indices\nlet slice1 = tensor.slice(s![-1, ..])?;\nassert_eq!(slice1.shape(), \u0026[6]);\n\nlet slice2 = tensor.slice(s![-2..-1, ..])?;\nassert_eq!(slice2.shape(), \u0026[1, 6]);\n\nlet slice3 = tensor.slice(s![.., ..-1])?;\nassert_eq!(slice3.shape(), \u0026[4, 5]);\n\n// 14. Stepped slicing with macro\nlet tensor2 = Tensor::\u003ci32\u003e::arange(24)?.view(\u0026[6, 4])?;\nlet slice = tensor2.slice(\u0026[step![0.., 2]])?;\nassert_eq!(slice.shape(), \u0026[3, 4]);\n\n// 15. Multiple step ranges\nlet two_steps = tensor2.slice(\u0026[step![-6..=-2, 2], step!(.., 2)])?;\nassert_eq!(two_steps.shape(), \u0026[3, 2]);\n\n// 16. Mixed slicing: single index and range\nlet tensor3 = Tensor::\u003ci32\u003e::arange(24)?.view(\u0026[2, 3, 4])?;\nlet mixed = tensor3.slice(s![0, 0..2, ..])?;\nassert_eq!(mixed.shape(), \u0026[2, 4]);\n\n// More..\n\n```\n\n---\n\n### par-iter\n\n#### Basic Usage\n```rust\nuse par_iter::ParIter;\n\n// Parallel map and collect\nlet data = (1..=10).collect::\u003cVec\u003c_\u003e\u003e();\nlet doubled: Vec\u003c_\u003e = data.par_iter().map(|\u0026x| x * 2).collect();\nassert_eq!(doubled, vec![2, 4, 6, 8, 10, 12, 14, 16, 18, 20]);\n\n// Parallel for_each with enumerate\nlet mut data = vec![0; 20];\ndata\n    .par_iter_mut()\n    .enumerate()\n    .for_each(|(i, val)| {\n        *val = i as i32 * 2;\n    });\nassert_eq!(data, (0..20).map(|i| i * 2).collect::\u003cVec\u003c_\u003e\u003e());\n```\n\n#### Advanced Combinators\n```rust\nuse par_iter::ParIter;\n\n// Parallel zip\nlet a = vec![1, 2, 3, 4];\nlet b = vec![10, 20, 30, 40];\nlet mut result = vec![0; 4];\na.par_iter()\n    .zip(b.par_iter())\n    .zip(result.par_iter_mut())\n    .for_each(|((x, y), r)| {\n        *r = x + y;\n    });\nassert_eq!(result, vec![11, 22, 33, 44]);\n\n// Parallel find\nlet data = (0..1000).collect::\u003cVec\u003c_\u003e\u003e();\nlet found = data.par_iter().find(|\u0026\u0026x| x == 333);\nassert_eq!(found, Some(\u0026333));\n\n// Parallel reduce\nlet data = (0..1000).collect::\u003cVec\u003c_\u003e\u003e();\nlet sum = data.par_iter().map(|\u0026x| x).reduce(0, |acc, x| acc + x);\nassert_eq!(sum, 499500);\n\n// Parallel chunked processing\nlet mut data = vec![0; 16];\nlet chunk_size = 4;\ndata\n    .par_chunks_mut(chunk_size)\n    .enumerate()\n    .for_each(|(chunk_idx, chunk)| {\n        for (i, val) in chunk.iter_mut().enumerate() {\n            *val = (chunk_idx * chunk_size + i) as i32;\n        }\n    });\nassert_eq!(data, (0..16).collect::\u003cVec\u003c_\u003e\u003e());\n```\n\n#### Matrix multiplication with Tensors\n\n```rust\nlet a = Tensor::\u003ci32\u003e::new((1..=12).collect(), \u0026[3, 4])?;\nlet b = Tensor::\u003ci32\u003e::new((1..=12).collect(), \u0026[4, 3])?;\n\nlet mut result_data = vec![0; 3 * 3];\n\na.par_rows()\n    .cartesian_product(b.transpose(0, 1)?.par_rows())\n    .zip(result_data.par_iter_mut())\n    .try_for_each(|(((_, row_tensor), (_, col_tensor)), v)| {\n        *v = row_tensor.dot(\u0026col_tensor)?;\n        Ok(())\n    })?;\n\nassert_eq!(result_data, vec![70, 80, 90, 158, 184, 210, 246, 288, 330])\n\n```\n\n---\n\n### small-vec\n\n#### Basic Usage\n```rust\nuse small_vec::{SmallVec, small_vec};\n\n// Stack-allocated for small sizes\nlet mut v: SmallVec\u003ci32, 4\u003e = small_vec![1, 2, 3];\nv.push(4);\nv.push(5); // May move to heap if capacity exceeded\nassert_eq!(\u0026v[..], \u0026[1, 2, 3, 4, 5]);\n```\n\n#### Capacity and Heap Promotion\n```rust\nuse small_vec::{SmallVec, small_vec};\n\nlet mut v: SmallVec\u003ci32, 2\u003e = small_vec![];\nv.push(1);\nv.push(2);\nv.push(3); // Moves to heap\nassert_eq!(v, small_vec![1, 2, 3]);\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freinterpretcat%2Fzero-depend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freinterpretcat%2Fzero-depend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freinterpretcat%2Fzero-depend/lists"}