"Fossies" - the Fresh Open Source Software Archive

Member "asymptote-2.61/tests/array/transpose.asy" (18 Nov 2019, 1096 Bytes) of package /linux/misc/asymptote-2.61.src.tgz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 import TestLib;
    2 import math;
    3 
    4 StartTest("transpose");
    5 int n=3;
    6 real[][] a=new real[n][n]; 
    7 real[][] b=new real[n][n]; 
    8 for(int i=0; i < n; ++i) {
    9   for(int j=0; j < n; ++j) {
   10     a[i][j]=b[j][i]=rand();
   11   }
   12 }
   13 
   14 bool operator == (real[][] a, real[][] b)
   15 {
   16   int n=a.length;
   17   for(int i=0; i < n; ++i)
   18     if(!all(a[i] == b[i])) return false;
   19   return true;
   20 }
   21 
   22 bool operator == (real[][][] a, real[][][] b)
   23 {
   24   int n=a.length;
   25   for(int i=0; i < n; ++i) {
   26     real[][] ai=a[i];
   27     real[][] bi=b[i];
   28     int m=ai.length;
   29     for(int j=0; j < m; ++j) {
   30       if(!all(ai[j] == bi[j])) return false;
   31     }
   32   }
   33   return true;
   34 }
   35 
   36 assert(a == transpose(b));
   37 
   38 int n=3;
   39 real[][][] a=new real[n][n][n]; 
   40 real[][][] b=new real[n][n][n]; 
   41 real[][][] c=new real[n][n][n]; 
   42 real[][][] d=new real[n][n][n]; 
   43 for(int i=0; i < n; ++i) {
   44   for(int j=0; j < n; ++j) {
   45     for(int k=0; k < n; ++k) {
   46       a[i][j][k]=b[j][i][k]=c[i][k][j]=d[k][j][i]=rand();
   47     }
   48   }
   49 }
   50 
   51 assert(a == transpose(b,new int[] {1,0,2}));
   52 assert(a == transpose(c,new int[] {0,2,1}));
   53 assert(a == transpose(d,new int[] {2,1,0}));
   54 
   55 EndTest();