Transpose an arbitrarily sized rectangular Matrix.




 
#include<hopper.h>
#proto showarraydata(_X_)
main:
  .stack 12
  nCols=0, nRows=0,nDims=0
  A=-1,{5,11} rand array(A),mulby(10),ceil,mov(A)
  {"ORIGINAL ARRAY :\n",A}
 
  _show array data(A)
 
  /* transpose */
  TA=0,{nCols,nRows} nan array(TA)
  Limit = nRows
  {nRows}gthan(nCols) do{ Limit = nCols }
 
  for (i=1, {i} lethan (Limit), ++i)
     [i,i:end]get(A), [i:end,i]put(TA)
     [i:end,i]get(A), [i,i:end]put(TA)
  next
  clear mark
  {"ARRAY TRANSPOSE:\n",TA}println
  _show array data(TA)
exit(0)
 
.locals
show array data(A)
  {"\nSIZE ARRAY : "},size=0,size(A),cpy(size),
  dims(size,nDims)
  rows(size,nRows)
  cols(size,nCols)
  {"\nDIMENSION = ",nDims,"; ROWS = ",nRows,"; COLS = ",nCols,"\n"}, println
back
 