C/Fortran Layouts: Default Language Roots

NumPy arrays default to C-contiguous (row-major) order, aligning with Python and C's memory storage, while Fortran-contiguous (column-major) matches Fortran's default, fundamentally influencing data access patterns.

The top 3

  1. C vs. Fortran: Origins of Memory Layout Divide: C adopted row-major order due to its array syntax and alignment with Western reading conventions, while Fortran chose column-major to align with mathematical linear algebra and early hardware for scientific computing.
  2. Cache Performance: Row-Major vs. Column-Major Impact: Accessing contiguous memory is crucial for cache efficiency; C's row-major layout excels with row-wise loops, while Fortran's column-major layout optimizes column-wise access, leading to significant speed differences if loop order is mismatched.
  3. Design Philosophies Behind Layout Defaults: C's row-major choice simplifies pointer arithmetic and aligns with its 'array of arrays' concept, whereas Fortran's column-major supports mathematical matrix operations and early vector processing hardware.

Sources

Open the full topic