#array #multi-dimensional #slice #multidimensional

multiarray

Small Rust library for handling multi-dimensional data

4 releases

Uses old Rust 2015

0.1.3 Sep 30, 2015
0.1.2 Sep 30, 2015
0.1.1 Sep 30, 2015
0.1.0 Sep 30, 2015

#2594 in Algorithms

Download history 25/week @ 2024-03-15 41/week @ 2024-03-22 70/week @ 2024-03-29 26/week @ 2024-04-05 35/week @ 2024-04-12 25/week @ 2024-04-19 25/week @ 2024-04-26 27/week @ 2024-05-03 28/week @ 2024-05-10 33/week @ 2024-05-17 31/week @ 2024-05-24 31/week @ 2024-05-31 18/week @ 2024-06-07 28/week @ 2024-06-14 30/week @ 2024-06-21 7/week @ 2024-06-28

88 downloads per month
Used in candlelighter

MIT/Apache

27KB
523 lines

This library provides ways to create and deal with multi-dimensional arrays. It basically tries to generalize Box<[T]>, &[T] and &mut[T] to multiple dimensions with some convenient methods that allow you to slice views, create lower-dimensional slices of it, subsampled or reversed views or even swap dimensions (for example, to create a transposed view of a 2D matrix).

Example

In the following example you'll see how a 3D array and two views into it (2D and 1D) can be created.

use multiarray::*;

let mut voxels = Array3D::new([3,4,5], 0); // 3x4x5 ints
voxels[[0,0,0]] = 1;
voxels[[1,2,3]] = 23;
voxels[[2,3,4]] = 42;
assert!(voxels[[1,2,3]] == 23);
let slice = voxels.eliminated_dim(1, 2);   // 2D slice
assert!(slice[[1,3]] == 23);
let lane = slice.eliminated_dim(1, 3);     // 1D lane
assert!(lane[1] == 23);

Here, slice is a 2D slice of the 3D volume (at y=2) and lane is a one-dimensional view that also acts as an ExactSize/DoubleEnded iterator.


lib.rs:

This crate provides types to deal with multi-dimensional data. It basically tries to generalize over Box<[T]>, &[T] and &mut [T] to multiple dimensions. As a side effect, it also supports one-dimensional arrays that have a stride other than one.

Examples

Here's an example of a 3D array. One 2D view and one 1D view into part of the data is created.

use multiarray::*;

let mut voxels = Array3D::new([3,4,5], 0); // 3x4x5 ints
voxels[[0,0,0]] = 1;
voxels[[1,2,3]] = 23;
voxels[[2,3,4]] = 42;
assert!(voxels[[1,2,3]] == 23);
let slice = voxels.eliminated_dim(1, 2);   // 2D slice
assert!(slice[[1,3]] == 23);
let lane = slice.eliminated_dim(1, 3);     // 1D lane
assert!(lane[1] == 23);

Please note that [usize; N] is used as index. For convenience the one-dimensional case also supports usize as index in addition to [usize; 1], the one-dimensional views are convertible from borrowed slices (&[T] and &mut[T]) via std::convert::{ From, Into } and also implement the iterator traits Iterator, ExactSizeIterator and DoubleEndedIterator.

Dependencies