Search code examples
arraysnumpymultidimensional-arraycontiguous

When are arrays C-contiguous and F-contiguous simultaneously?


Under what conditions can arrays be C-contiguous and F-contiguous simultaneosly?

I can think of the following:

  • The 1D case that is trivially C- and F-contiguous.
  • Similarly, multi-dimensional arrays where all dimensions are singleton dimensions except for one.

Are there any others?


Solution

  • You got it. An array is both C and Fortran contiguous (i.e. is both row major and column major) when it has at most 1 dimension longer than 1. Basically, vectors and scalars, plus degenerate arrays with additional "unnecessary" dimensions.