1
2 #include "aux2/transpose.h"
3 #include "aux2/transpose2.h"
4 #include "aux1/copy.h"
5 //#include "aux2/copy2d.h"
6 //#include "aux1/auxprint.h"
7 //#include "aux1/aux1double.h"
8 #include "perm/permq.h" // is_identity()
9
10 #include "fxtio.h"
11
12 #include "fxttypes.h"
13 #include "fxtalloca.h"
14
15 #include <cstdlib> // strtoul()
16
17
18 #include "test.h" // last to include
19
20
21
22 #define SRC(k) (((unsigned long long)(k)*nc)%n1) // note: overflow if k*nc >= 2^64
23 template <typename Type>
24 int
is_transposed(const Type * f,ulong nr,ulong nc)25 is_transposed(const Type *f, ulong nr, ulong nc)
26 // check whether array has values as if filled
27 // with set_seq(f, nr*nc, 0, 1) and then transposed
28 {
29 ulong n = nr * nc;
30 ulong n1 = n - 1;
31 if ( n<=2 ) return 1;
32
33 // if ( (1==nr) || (1==nc) ) return is_seq(f, n);
34 if ( (1==nr) || (1==nc) ) return is_identity(f, n);
35
36 for (ulong k=0; k<n1; ++k)
37 {
38 ulong t = SRC(k);
39 if ( f[k] != t )
40 {
41 cout << " element # " << k
42 << " should be == " << t
43 << " but equals " << f[k] << endl;
44 return 0;
45 }
46 }
47
48 return 1;
49 }
50 // -------------------------
51 #undef SRC
52
53 template <typename Type>
54 void
test_print2d(const Type * f,ulong nr,ulong nc)55 test_print2d(const Type *f, ulong nr, ulong nc)
56 {
57 // cout.precision(21);
58
59 for (ulong k=0,idx=0; k<nr; ++k)
60 {
61 cout << k << ": ";
62 for (ulong j=0; j<nc; ++j,++idx)
63 {
64 cout << "(# "<< idx << ")=";
65 cout << f[idx] << " ";
66 }
67 cout << endl;
68 }
69 cout << endl;
70 }
71 // -------------------------
72
73 int
main(int argc,char ** argv)74 main(int argc, char **argv)
75 {
76 cout << "Running tests for permutations ... " << endl;
77
78 ulong minldn = 0, maxldn = 14;
79 if ( argc>1 ) minldn = strtoul(argv[1], nullptr, 10);
80 if ( argc>2 ) maxldn = strtoul(argv[2], nullptr, 10);
81
82 ulong n = 1UL<<maxldn;
83 double *tar = new double[n];
84 double *fr = new double[n];
85 double *gr = new double[n];
86 const double *const ar = tar;
87
88 for (ulong ldn=minldn; ldn<=maxldn; ++ldn)
89 {
90 n = 1UL<<ldn;
91 cout << "==================== LDN = " << ldn
92 << " N = " << n << " :" << endl;
93
94 for (ulong ldnr=0; ldnr<=ldn; ++ldnr)
95 {
96 ulong ldnc = ldn - ldnr;
97 ulong nr = (1UL<<ldnr);
98 ulong nc = (1UL<<ldnc);
99
100 set_seq(tar, n, 0.0, 1.0);
101 cout << "\n----- nr = " << nr << " nc = " << nc << " : -----" << endl;
102
103 EQUIV_REAL( acopy(ar, fr, n);
104 acopy(ar, gr, n);
105 transpose(gr, nr, nc);
106 transpose(gr, nc, nr); );
107
108 EQUIV_REAL( acopy(ar, fr, n);
109 acopy(ar, gr, n);
110 transpose2(gr, nr, nc, nullptr);
111 transpose2(gr, nc, nr, nullptr); );
112
113 EQUIV_REAL( acopy(ar, fr, n);
114 acopy(ar, gr, n);
115 transpose(gr, nr, nc, nullptr);
116 transpose(gr, nc, nr, nullptr); );
117
118 EQUIV_REAL( acopy(ar, fr, n); transpose(fr, nr, nc);
119 acopy(ar, gr, n); transpose(gr, nr, nc); );
120
121
122 // acopy(ar, fr, n); transpose(fr, nr, nc);
123 // if ( 0==is_transposed(fr, nr, nc) )
124 // {
125 // test_print2d(ar, nr, nc);
126 // test_print2d(fr, nr, nc);
127 // test_print2d(fr, nc, nr);
128 // exit(33);
129 // }
130
131 }
132 }
133
134 cout << "\nOK, all passed." << endl;
135 return 0;
136 }
137 // -------------------------
138
139