chickadee » generalized-arrays » array-swap-axes

array-swap-axes array to fromprocedure

Perform a triadic transposition of the to and from axes. This is equivalent to swapping the ordering of the two provided axes in the array's shape. 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.

Both the to and from axes must be fixnums between 0 and the less than the rank of the array.

(import generalized-arrays

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

(test "Shape of array a"
      (make-default-interval (vector 2 1 3 4))
      (array-shape a))

(define b
  (array-swap-axes a 0 1))

(test "Shape of array b"
      (make-default-interval (vector 1 2 3 4))
      (array-shape b))

(define c
  (array-swap-axes b 0 3))

(test "Shape of array c"
      (make-default-interval (vector 4 2 3 1))
      (array-shape b))

(define d
  (array-swap-axes a 2 3))

(test "Shape of array d"
      (make-default-interval (vector 2 1 4 3))
      (array-shape d))