  function Transpose(float *r, *m, int nx=4,ny=0) as float*
  =========================================================
  ' r  resulting transposed matrix ptr
  ' m  source matrix ptr
  ' nx source matrix columns
  ' ny source matrix rows
  '
  'using striding pointers instead of indexes
  '
  int i  ' major iterator
  int j  ' minor iterator
  int mx ' column stride
  int my ' row stride
  sys*mm ' striding source ptr
  sys*rr ' striding transpose ptr
  '
  if ny=0
    ny=nx
  endif
  mx=nx*sizeof float
  my=sizeof float
  @rr=@r
  @mm=@m
  for i=0 to <nx   'transposed rows
    for j=0 to <ny 'tranposed column
      rr=mm
      @rr+=my 
      @mm+=mx
    next
    @mm=@mm+my-(ny*mx)
    '@mm=@m
  next
  return @r
  end function


float M=
{
  1, 5, 9,13,17,
  2, 6,10,14,18,
  3, 7,11,15,19,
  4, 8,12,16,20
}

float R[20]

Transpose R,M,5,4

'SHOW
uses console
indexbase 0
int i,j,k
for i=0 to <20 step 5 'each line
  for j=0 to <5  'each value
    k=i+j
    print M[k] tab
  next
  print cr
next
print cr cr
for i=0 to <20 step 4 'each line
  for j=0 to <4  'each value
    k=i+j
    print R[k] tab
  next
  print cr
next
print cr cr

pause



 