Issue #8131 Contiguous Array Slices

Hi

I’ve run into the non-contiguous array performance warning (issue #8131) when slicing a 2d array.

I’ve seen the ‘ellipsis’ work around for looping over the inner dimension of an array slice, but I want to loop over the outer dimension of an array slice. The ‘ellipsis’ workaround doesn’t seem to work in the case, or am I missing something?

This is my test, which generates the non-contiguous array warning, as posted in a comment for issue #8131

@njit
def test(array2d):   
    slice2d = array2d[:, :4]  
    for i in range(len(array2d)):
        #print(slice2d[i].flags)
        _ = slice2d[i] @ slice2d[i]  # Stupid calculation to illustrate point.
    return

if I replace slice2d = array2d[:, :4] with slice2d = array2d[..., :4] , the ‘ellipsis’ workaround, I get the same warning.

Any help in getting rid of the warning would be appreciated.

Kind regards

How about _ = array2d[i, :4] @ array2d[i, :4]?

1 Like

Hi Milton

Thank you for your reply. My code is a simplified example of my actual code to illustrate the point. I’m using multiple slices to name the fields of a passed 2d array with more intuitive names, so I’m really hoping to use the slice syntax without the performance warning.