{"id":14992091,"url":"https://github.com/JErnestoMtz/rapl","last_synced_at":"2025-09-25T14:30:50.035Z","repository":{"id":149995763,"uuid":"595878598","full_name":"JErnestoMtz/rapl","owner":"JErnestoMtz","description":"Rank Polymorphic array library for Rust.","archived":false,"fork":false,"pushed_at":"2023-07-29T03:52:02.000Z","size":4977,"stargazers_count":103,"open_issues_count":8,"forks_count":3,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-09-25T16:09:21.282Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/JErnestoMtz.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}},"created_at":"2023-02-01T01:43:26.000Z","updated_at":"2024-09-12T09:40:53.000Z","dependencies_parsed_at":"2024-09-25T00:34:18.611Z","dependency_job_id":null,"html_url":"https://github.com/JErnestoMtz/rapl","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JErnestoMtz%2Frapl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JErnestoMtz%2Frapl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JErnestoMtz%2Frapl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JErnestoMtz%2Frapl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JErnestoMtz","download_url":"https://codeload.github.com/JErnestoMtz/rapl/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234200165,"owners_count":18795139,"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","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":"2024-09-24T15:00:43.674Z","updated_at":"2025-09-25T14:30:44.457Z","avatar_url":"https://github.com/JErnestoMtz.png","language":"Rust","funding_links":[],"categories":["Scientific Computation"],"sub_categories":[],"readme":"# rapl\n[![Documentation](https://docs.rs/rapl/badge.svg)](https://docs.rs/rapl)\n[![Crate](https://img.shields.io/crates/v/rapl.svg)](https://crates.io/crates/rapl)\n\nNote: `rapl` is in early development and is  not optimized for performance, is not recommended for production applications.\n\n`rapl` is mathematical  computing Rust library that provides a simple way of working with N-dimensional array, along with a wide range of mathematical functions to manipulate them. It takes inspiration from NumPy and APL, with the primary aim of achieving maximum ergonomics and user-friendliness while maintaining generality. \n\nOur goal is to make Rust scripting as productive as possible, and make Rust a real option when it comes to  numerical computing and data science. Check out the [examples](https://github.com/JErnestoMtz/rapl/tree/main/examples).\n\nOut of the box `rapl` provides features like **co-broadcasting, rank type checking, native complex number support**, among many others:\n\n```Rust\nuse rapl::*;\nfn main() {\n    let a = Ndarr::from([1 + 1.i(), 2 + 1.i()]);\n    let b = Ndarr::from([[1, 2], [3, 4]]);\n    let r = a + b - 2;\n    assert_eq!(r, Ndarr::from([[1.i(), 2 + 1.i()],[2 + 1.i(), 4 + 1.i()]]));\n}\n```\n\n### Array initialization\nThere are multiple handy ways of initializing N-dimensional arrays (or `Ndarr`).\n- From Native Rust arrays to `Ndarr`.\n```Rust \nlet a = Ndarr::from([\"a\",\"b\",\"c\"]); \nlet b = Ndarr::from([[1,2],[3,4]]);\n```\n- From ranges.\n```Rust\nlet a = Ndarr::from(1..7).reshape(\u0026[2,3])\n```\n- From `\u0026str`\n```Rust\nlet chars = Ndarr::from(\"Hello rapl!\"); //Ndarr\u003cchar,U1\u003e\n```\n- Others:\n```Rust \nlet ones: Ndarr\u003cf32, 2\u003e = Ndarr::ones(\u0026[4,4]);\nlet zeros : Ndarr\u003ci32, 3\u003e= Ndarr::zeros(\u0026[2,3,4]);\nlet letter_a = Ndarr::fill(\"a\", \u0026[5]);\nlet fold = Ndarr::new(data: \u0026[0, 1, 2, 3], shape: [2, 2]).expect(\"Error initializing\");\n```\n- linspace, logspace, geomspace\n```Rust\n    let linear = Ndarr::linspace(0, 9, 10);\n    assert_eq!(linear,Ndarr::from(0..10));\n\n    let logarithmic = Ndarr::logspace(0.,9., 10., 10);\n    assert!(logarithmic.approx(\u0026Ndarr::from([1.,1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9])));\n\n    let geom = Ndarr::geomspace(1.,256., 9);\n    assert!(geom.approx(\u0026Ndarr::from([1., 2., 4., 8., 16., 32., 64., 128., 256.])));\n\n```\n### Random array creation\nYou can easily create random array of any shape:\n```Rust\n//Normal distribution\nlet arr_norm = NdarrRand::normal(low: 0f32, high: 1f32, shape: [2, 2], Seed: Some(1234));\n//Normal distribution\nlet arr_uniform = NdarrRand::uniform(low: 0f32, high: 1f32, shape: [10], Seed: None);\n//Choose between values\nlet arr_choose = NdarrRand::choose(\u0026[1, 2, 3, 4, 5], [3, 3], Some(1234));\n```\n\n### Element wise operations\n- Arithmetic operation with with scalars\n```Rust\nlet ones: Ndarr\u003ci32, 2\u003e = Ndarr::ones(\u0026[4,4]);\nlet twos = ones + 1;\nlet sixes = twos * 3;\n```\n- Arithmetic operation between `Ndarr`s,\n```Rust\nlet a = Ndarr::from([[1,2],[3,4]]);\nlet b = Ndarr::from([[1,2],[-3,-4]]);\n\nassert_eq!(a + b, Ndarr::from([[2,4],[0,0]]))\n```\nNote: If the shapes are not equal `rapl` will automatically broadcast the arrays into a compatible shape (if it exist) and perform the operation.\n- Math operations including trigonometric and activation functions.\n```Rust\nlet x = Ndarr::from([-1.0 , -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0]);\nlet sin_x = x.sin();\nlet cos_x = x.cos();\nlet tanh_x = x.tanh();\n\nlet abs_x = x.abs();\nlet relu_x = x.relu();\n```\n- Map function\n```Rust\nlet a = Ndarr::from([[1,2],[3,4]]);\nlet mapped = a.map(|x| x*2-1);\n```\n### Monadic tensor operations\n- Transpose\n```Rust\nlet arr = Ndarr::from([[1,2,3],[4,5,6]]);\t\nassert_eq!(arr.shape(), [2,3]);\nassert_eq!(arr.clone().t().shape, [3,2]); //transpose\n```\n- Reshape\n```Rust\nlet a = Ndarr::from(1..7).reshape(\u0026[2,3]).unwrap();\n```\n- Slice\n```Rust\nlet arr = Ndarr::from([[1,2],[3,4]]);\n\nassert_eq!(arr.slice_at(1)[0], Ndarr::from([1,3]))\n```\n- Reduce\n```Rust\nlet sum_axis = arr.clone().reduce(1, |x,y| x + y).unwrap();\nassert_eq!(sum_axis, Ndarr::from([6, 15])); //sum reduction\n```\n- Scan right an left\n```Rust\n let s = Ndarr::from([1,2,3]);\n let cumsum = s.scanr( 0, |x,y| x + y);\n assert_eq!(cumsum, Ndarr::from([1,3,6]));\n```\n- Roll\n```Rust\nlet a = Ndarr::from([[1, 2], [3, 4]]);\nassert_eq!(a.roll(1, 1), Ndarr::from([[2, 1], [4, 3]]))\n```\n\n### Dyatic tensor operations\n- Generalized matrix multiplication between compatible arrays\n```Rust\nuse rapl::*\nuse rapl::ops::{mat_mul};\nlet a = Ndarr::from(1..7).reshape(\u0026[2,3]).unwrap();\nlet b = Ndarr::from(1..7).reshape(\u0026[3,2]).unwrap();\n    \nlet matmul = mat_mul(a, b))\n```\n- [APL](https://en.wikipedia.org/wiki/APL_(programming_language)) inspired Inner Product.\n```Rust\n    let a = Ndarr::from(1..7).reshape(\u0026[2,3]).unwrap();\n    let b = Ndarr::from(1..7).reshape(\u0026[3,2]).unwrap();\n    \n    let inner = rapl::ops::inner_product(|x,y| x*y, |x,y| x+y, a.clone(), b.clone());\n    assert_eq!(inner, rapl::ops::mat_mul(a, b))\n\n```\n- Outer Product.\n\n```Rust\n    let suits = Ndarr::from([\"♣\",\"♠\",\"♥\",\"♦\"]);\n    let ranks = Ndarr::from([\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"10\",\"J\",\"Q\",\"K\",\"A\"]);\n\n    let add_str = |x: \u0026str, y: \u0026str| (x.to_owned() + y);\n\n    let deck = ops::outer_product( add_str, ranks, suits).flatten(); //All cards in a deck\n```\n### Complex numbers\nYou can ergonomically do operations between native numeric types and complex types `C\u003cT\u003e` with a simple and clean interface. \n``` Rust\nuse rapl::*;\n// Complex sclars\n    let z = 1 + 2.i();\n    assert_eq!(z, C(1,2));\n    assert_eq!(z - 3, -2 + 2.i());\n```\n\nSeamlessly work with complex numbers, and complex tensors.\n```Rust\nuse rapl::*;\n// Complex tensors\nlet arr = Ndarr::from([1, 2, 3]);\nlet arr_z = arr + -1 + 2.i();\nassert_eq!(arr_z, Ndarr::from([C(0,2), C(1,2), C(2,2)]));\nassert_eq!(arr_z.im(), Ndarr::from([2,2,2]));\n```\n### Dead Simple 1D and 2D FFT\n```Rust\n    let signal = Ndarr::linspace(-10., 10., 100).sin();\n    let signal_fft = signal.to_complex().fft();\n```\n\n### Image to Array and Array to Image conversion\nYou can easily work with images of almost any format. `rapl` provides  helpful functions to open images as both RGB and Luma `Ndarr`, and also save them to your preferred format.\n\n```Rust\nuse rapl::*;\nuse rapl::utils::rapl_img;\n\nfn main() {\n    //open RGB image as  Ndarr\u003cu8,3\u003e\n    let img: Ndarr\u003cu8,U3\u003e = rapl_img::open_rgbu8(\u0026\"image_name.jpg\").unwrap();\n    //Split RGB channels by Slicing along 3'th axis.\n    let channels: Vec\u003cNdarr\u003cu8,U2\u003e\u003e = img.slice_at(2);\n    //select blue channel and save it as black and white image.\n    channels[2].save_as_luma(\u0026\"blue_channel.png\", rapl_img::ImageFormat::Png);\n}\n```\n### Features in development:\n- [x] Port to stable Rust\n- [x] Native support for complex numbers.\n- [x] Line space and meshigrid initialization.\n- [x] Random array creation.\n- [x] 1D and 2D FFT.\n- [ ] Matrix inversion.\n- [x] Image to array conversion.\n- [x] Array to image conversion.\n- [x] APL-inspired rotate function.\n- [x] Commonly use ML functions like Relu, Softmax etc.\n- [ ] Support for existing plotting libraries in rust.\n- [ ] Mutable slicing.\n- [ ] Other Linear algebra functionalities: Eigen, LU, Gauss Jordan, Etc.\n- [ ] Automatic differentiation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJErnestoMtz%2Frapl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FJErnestoMtz%2Frapl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJErnestoMtz%2Frapl/lists"}