warlock-labs / dimensionals

Rust native N dimensional arrays
MIT License
16 stars 3 forks source link

Dimensionals

License Crates.io Docs CI

Dimensionals is a Rust library for working with n-dimensional data. It provides a flexible and efficient multidimensional array implementation with a generic storage backend over generic number types.

Features

Usage

Add this to your Cargo.toml:

[dependencies]
dimensionals = "0.1.0"

Here's a basic example of creating and using a matrix:

use dimensionals::{matrix, Dimensional, LinearArrayStorage};

fn main() {
    let m: Dimensional<i32, LinearArrayStorage<i32, 2>, 2> = matrix![
        [1, 2, 3],
        [4, 5, 6]
    ];
    assert_eq!(m[[0, 0]], 1);
    assert_eq!(m[[1, 1]], 5);

    // Element-wise addition
    let m2 = &m + &m;
    assert_eq!(m2[[0, 0]], 2);
    assert_eq!(m2[[1, 1]], 10);

    // Scalar multiplication
    let m3 = &m * 2;
    assert_eq!(m3[[0, 0]], 2);
    assert_eq!(m3[[1, 1]], 10);

    // Iteration
    for &value in m.iter() {
        println!("{}", value);
    }

    // Matrix multiplication
    let m4: Dimensional<i32, LinearArrayStorage<i32, 2>, 2> = matrix![
        [7, 8],
        [9, 10],
        [11, 12]
    ];
    let product = m.dot(&m4);
    assert_eq!(product[[0, 0]], 58);
}

For more examples and usage details, see the API documentation.

Core Concepts

Performance

The LinearArrayStorage backend stores elements in a contiguous Vec<T> and supports both row-major and column-major layouts. This provides good cache locality for traversals. The storage computes strides for efficient indexing.

Roadmap

The following features and improvements are planned for future releases:

Contributing

Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests on the GitHub repository.

License

This project is licensed under the MIT License.

Contact

Warlock Labs - https://github.com/warlock-labs

Project Link: https://github.com/warlock-labs/dimensionals