Skip to content

Check for C-style ordering in numpy array is checking only if its not F-style ordering #2122

@vnktshr21

Description

@vnktshr21

We use numpy.isfortran to check if a incoming array is following C-style index ordering. We do this check since the rest of the layers underneath assumes C-style ordering. This check becomes more critical in case of multidimensional arrays since usually those multidimensional arrays in python API method would be handled as 1D array in the C API and this translation fails if not C-style ordering. The numpy.isfortran only ensures that the incoming array is not F-contiguous. However, when it returns false, there is no guarantee that the incoming array is always C-contiguous. If the incoming array has undergone some manipulation(like slicing with steps, transposing, or fancy indexing) before getting passed, then it is possible that the memory layout is not contiguous and isfortran check will miss catching this. We should instead be explicitly checking for C-contiguous layout using numpy.flags.c_contiguous to ensure the layout is as the C API expects it to be.

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