AFF --- A container for numbers (array) by Friederich and Forbriger.
shapetest.cc
Go to the documentation of this file.
1 
42 #define AFF_SHAPETEST_CC_VERSION \
43  "AFF_SHAPETEST_CC V1.3"
44 
45 #include<iostream>
46 #include<aff/dump.h>
47 #include<aff/shaper.h>
49 
50 using std::cout;
51 using std::endl;
52 using namespace aff;
53 
72 /*----------------------------------------------------------------------*/
73 
75 void section(const char* s, const char l='-')
76 {
77  cout << endl << s << endl;
78  const char* p=s;
79  while (*p) { cout << l; ++p; }
80  cout << endl;
81 }
82 
83 /*----------------------------------------------------------------------*/
84 
86 const char* bvalue(const bool& b)
87 { if (b) return("true"); return("false"); }
88 
89 /*----------------------------------------------------------------------*/
90 
92 #define BOOLIS( S ) cout << " *** " << #S << ": " << bvalue(S);
93 
94 /*----------------------------------------------------------------------*/
95 
97 void steppers(const Strided& shape, const int& nmax=30)
98 {
99  StridedStepper s1(shape), s2(shape);
100  s2.tolast();
101  for (int i=0; i<nmax; i++)
102  {
103  cout.width(3); cout << i+1;
104  cout << " ";
105  cout.width(5); cout << s1.current() << "=[";
106  for (int j=0; j<Strided::Mmax_dimen; j++)
107  {
108  if (j) cout << ", ";
109  cout.width(2); cout << s1.index(j);
110  }
111  cout << "] ";
112  cout.width(5); cout << bvalue(s1.more());
113  cout.width(6); cout << bvalue(s1.valid());
114  cout << " ";
115  cout.width(5); cout << s2.current() << "=[";
116  for (int j=0; j<Strided::Mmax_dimen; j++)
117  {
118  if (j) cout << ", ";
119  cout.width(2); cout << s2.index(j);
120  }
121  cout << "] ";
122  cout.width(5); cout << bvalue(s2.less());
123  cout.width(6); cout << bvalue(s2.valid());
124  cout << endl;
125  s1.incr();
126  s2.decr();
127  }
128 }
129 
130 /*======================================================================*/
131 
133 int main()
134 {
135  cout << AFF_SHAPETEST_CC_VERSION << endl;
136 
137  section("Test shape class Strided", '=');
138 
139  section("Test shaper class Shaper");
140 
141  cout << endl << "Basic usage:" << endl;
142  DUMP( Shaper(10)(12) );
143 
144 #ifdef ILLEGAL1
145 #warning intentionally compiling illegal code
146  cout << endl << "Illegal with limited dimensionality:" << endl;
147  DUMP( Shaper(2,10)(-12,12)(9)(2,7)(3,4) );
148 #endif
149 
150  cout << endl << "Usage for an external Fortran shape:" << endl;
151  DUMP( Shaper(1,6,10)(1,12,30)(1,10) );
152 
153  section("Test subarrays and slicing");
154 
155  DUMP( Shaper(10)(10)(10) );
156 
157  cout << endl;
158  DUMP( Strided(Shaper(10)(10)(10)).shrink(0,2,5) );
159 
160  cout << endl;
161  DUMP( Strided(Shaper(10)(10)(10)).shrink(2,5) );
162 
163  cout << endl;
164  DUMP( Strided(Shaper(10)(15)(20)).collapse(1,5) );
165 
166  cout << endl;
167  DUMP( Strided(Shaper(11,20)(11,20)(11,20)).shift(1,5) );
168 
169  cout << endl;
170  DUMP( Strided(Shaper(11,20)(11,20)(11,20)).setfirst(1,5) );
171 
172  section("Test stepper");
173 
174  {
175  cout << endl << "Basic functionality" << endl;
176  CODE( Strided shape(Shaper(3)(4)(2)(3)); )
177  DUMP( shape );
178  CODE( steppers(shape, shape.size()+10); )
179  }
180 
181  {
182  cout << endl << "Shape with gaps" << endl;
183  CODE( Strided shape(Shaper(0,9)(0,9)(0,9)(0,9)); )
184  DUMP( shape.shrink(0,3,5).shrink(1,4,6).shrink(2,5,7).shrink(3,6,8) );
185  CODE( steppers(shape, shape.size()+10); )
186  }
187 
188  {
189  cout << endl << "Small array" << endl;
190  CODE( Strided shape(Shaper(3,5,10)(3)); )
191  DUMP( shape );
192  CODE( steppers(shape, shape.size()+10); )
193  }
194 
195  section("Test offset functions");
196  {
197  CODE( Strided shape(Shaper(5)(10)(10)(10)); )
198  CODE( shape.shrink(0,2,4).shrink(1,3,7).shrink(2,5,6).shrink(3,2,3); )
199  CODE( dump_map(shape, 3); )
200  CODE( dump_map(shape, 2); )
201  CODE( dump_map(shape, 1); )
202  CODE( dump_map(shape, 0); )
203  CODE( steppers(shape, shape.size()); )
204  CODE( Strided copy(shape); )
205  CODE( copy.collapse(2,6).collapse(2,3).shift(0,1000).setfirst(1,50); )
206  CODE( dump_map(copy); )
207  CODE( copy=shape; )
208  CODE( copy.collapse(1,7).collapse(2,3).shift(0,1000).setfirst(1,50); )
209  CODE( dump_map(copy); )
210  }
211 }
212 
213 /* ----- END OF shapetest.cc ----- */
StridedStepper & decr()
decrement offset - return reference to itself
Root namespace of library.
Definition: array.h:148
Shape for a rectangular array layout.
Definition: strided.h:117
#define AFF_SHAPETEST_CC_VERSION
Definition: shapetest.cc:42
int main()
test shape class
Definition: shapetest.cc:133
void section(const char *s, const char l='-')
print headline
Definition: shapetest.cc:75
#define DUMP(A)
Dump any object through its dump function.
Definition: dump_macros.h:62
const TIndexVec & index() const
return current index vector for array access
void dump_map(const Strided &shape, const Tdim &i, std::ostream &os)
dump index mapping of shape
Definition: dump.cc:145
Stepper class for strided shapes (prototypes)
#define CODE(C)
Dump code and execute (works like echo)
Definition: dump_macros.h:82
static const Tdim Mmax_dimen
instantiate static member (otherwise the linker won&#39;t find it)
Definition: strided.h:123
StridedStepper & tolast()
set current element index to the last - return reference to itself
debug helpers (prototypes)
void steppers(const Strided &shape, const int &nmax=30)
cycle steppers
Definition: shapetest.cc:97
const Tsubscript & current() const
return current index value for Representation access
A stepper for all strided shapes.
const bool & valid() const
valid if not passed end or beginning
bool less() const
returns true if there are more elements in decr-direction
Shaper class for Fortran layout.
Definition: shaper.h:66
rectangular Fortran array layout (prototypes)
const char * bvalue(const bool &b)
print value of a bool
Definition: shapetest.cc:86