JErnestoMtz / rapl

Rank Polymorphic array library for Rust.
103 stars 3 forks source link

ArrayView implementation #36

Open JErnestoMtz opened 1 year ago

JErnestoMtz commented 1 year ago

I really wanted to avoid implementing ArrayView for Ndarr due to the unavoidable unsafe code. But at the end of the day it is a well tested strategy, and it will help a lot to improve the performance of many operations. But most importantly, if we want to eventually implement mutable slicing, I think there is no other way.

The idea of an ArrayView as far as I understand it, is sort of a reference to a Ndarr. It holds a pointer to the beginning of the Ndarr data, the shape and stride that can be calculated with the shape itself.

struct ArrayView<'a, T, R: Unsigned> {
    data: *const T,
    shape: Dim<R>,
    strides: Vec<usize>,
    _phantom: PhantomData<&'a T>,
}
DeliciousHair commented 1 year ago

unsafe is fine, just need to make sure the API to it is safe :-)