chickadee » generalized-arrays » array-transpose

array-transpose arrayprocedure

Performs a monadic transposition of the major through minor axes of the array. This is equivalent to reversing the ordering of the major through minor axes. This procedure returns an array view (i.e. satisfies array-view?) without copying any of the array's internal data or modifying the underlying storage-object.

(import generalized-arrays

(define a
  (make-array vector-storage-class
              (vector 1 2 3 4)

(test "Array dimensions are (1 2 3 4)"
      (make-default-interval (vector 1 2 3 4))
      (array-shape a))

(define a-t
  (array-transpose a))

;; For a rank-2 array, this would be swapping an #(i j) with #(j i)
(test "Transpose dimensions are (4 3 2 1)"
      (make-default-interval (vector 1 2 3 4))
      (array-shape a-t))

Note that while the internal storage-object is not modified, fold operations still iterate through the array's elements (specifically a-t in the example above) in lexicographic order according to the array's shape / interval. This may or may not provide efficient access into the storage-object, since sequential elements in lexicographic order may not necessarily be contiguous in memory.