Skip to content

Questions about compatibility between nalgebra and ndarray #473

@jturner314

Description

@jturner314

I'm working on implementing conversions between nalgebra and ndarray types. This looks fairly straightforward, but I have two questions:

  1. Does nalgebra support negative strides? From what I can tell, the answer is "no", but will you please confirm?

  2. Does nalgebra allow using strides that result in multiple indices pointing to the same element? ndarray allows this for immutable views (ArrayView) but not for mutable views (ArrayViewMut) due to Rust's aliasing rules. I'm somewhat surprised that nalgebra's mutable slices currently allow this:

    extern crate nalgebra as na;
    
    use na::DMatrixSliceMut;
    
    fn main() {
        let slice = &mut [1, 2, 3];
        let m = DMatrixSliceMut::from_slice_with_strides_mut(slice, 2, 3, 0, 1);
        // Prints:
        //   ┌       ┐
        //   │ 1 2 3 │
        //   │ 1 2 3 │
        //   └       ┘
        println!("{}", m);
    }

    This should be fine fine as long as nalgebra doesn't allow getting mutable references simultaneously for two different indices (e.g. with something like split_at). I'm just surprised at the current behavior, so I'd like to make sure it's intentional and not a bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions