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.
T
(implementing Num
and Copy
), number of dimensions N
, and storage backend S
LinearArrayStorage
backend with support for row-major and column-major layoutsvector!
and matrix!
)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.
T
: The type of data stored in the array (must implement Num
and Copy
).S
: The underlying storage mechanism for the array (must implement DimensionalStorage
).N
: The dimensionality of the array (const generic parameter).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.
The following features and improvements are planned for future releases:
Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests on the GitHub repository.
This project is licensed under the MIT License.
Warlock Labs - https://github.com/warlock-labs
Project Link: https://github.com/warlock-labs/dimensionals