row vs. column-major-order Aubrey Jaffer (17 May 2006 20:50 UTC)
Re: row vs. column-major-order Dimiter "malkia" Stanev (05 Oct 2006 07:15 UTC)
Re: row vs. column-major-order Aubrey Jaffer (07 Oct 2006 17:17 UTC)

row vs. column-major-order Aubrey Jaffer 17 May 2006 20:49 UTC

Whether array elements are stored in row- or column-major-order
matters to efficient cache use when the array is scanned.

I believe that Scheme array code would run faster in
column-major-order than it does in row-major-order.

The functions which enumerate each element of an array reverse the
indexes for each element access:

    (define (ra2v dims idxs)
      (if (null? dims)
	  (let ((val (apply array-ref ra (REVERSE idxs))))
	    ...)
	  (do ((idx (+ -1 (car dims)) (+ -1 idx)))
	      ((negative? idx) vect)
	    (ra2v (cdr dims) (cons idx idxs)))))
    (ra2v dims '())

But in column-major order the reverse is done only once:

    (define (ra2v dims idxs)
      (if (null? dims)
	  (let ((val (apply array-ref ra idxs)))
	    ...)
	  (do ((idx (+ -1 (car dims)) (+ -1 idx)))
	      ((negative? idx) vect)
	    (ra2v (cdr dims) (cons idx idxs)))))
    (ra2v (REVERSE dims) '())

Is Fortran's using column-major-order related to this?