Skip to content

Empty Array lead to "The strides must not allow any element to be referenced by two different indices" #1609

Description

@patengel

I tried to create an empty array with the following command:

let shape = (1, 0).strides((0, 0));
let ptr = std::ptr::dangling::<f64>();
unsafe { ArrayView2::from_shape_ptr(shape, ptr) }

It fails with "The strides must not allow any element to be referenced by two different indices".

But the slightly different code works:

let shape = (0, 1).strides((0, 0));
let ptr = std::ptr::dangling::<f64>();
unsafe { ArrayView2::from_shape_ptr(shape, ptr) }

My expectation would be that both variants work fine.

I think the bug is inside dim_stride_overlap, which fails before the first 0 dimension is found and therefore recognises that the complete array is empty.

By the way, I use (0, 0) strides, since ndarray does the same for empty array e.g. created via zeros function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions