AFF --- A container for numbers (array) by Friederich and Forbriger.

◆ main()

int main ( )

test array functionality

Definition at line 86 of file arraytest.cc.

References AFF_ARRAYTEST_CC_VERSION, CODE, aff::Array< T >::copyout(), DUMP, aff::dump_array(), section(), and aff::subarray().

87 {
88  cout << AFF_ARRAYTEST_CC_VERSION << endl;
89 
90  section("Test constructors", '=');
91  section("size-constructor");
92  {
93  CODE( Array<float> A(3,4); )
94  DUMP( A );
95  }
96  section("shape-constructor");
97  {
98  CODE( Array<float> A(Shaper(4,14)(12)(-5,5)); )
99  DUMP( A );
100  }
101 
102  /*----------------------------------------------------------------------*/
103 
104  section("Test assignment", '=');
105  {
106  CODE( Array<float> A(3,4); );
107  CODE( A=15.5; );
108  CODE( dump_array(A); );
109  CODE( A(2,3)=-2.; );
110  CODE( A(3,1)=-5.; );
111  CODE( dump_array(A); );
112  }
113 
114  /*----------------------------------------------------------------------*/
115 
116  section("Test access operators", '=');
117  {
118  CODE( Array<int> A(Shaper(-2,2)(10,16)(2)(-1,0)); );
119  section("fill array");
120  for(int i=A.f(0); i<=A.l(0); i++)
121  {
122  for(int j=A.f(1); j<=A.l(1); j++)
123  {
124  for(int k=A.f(2); k<=A.l(2); k++)
125  {
126  for(int l=A.f(3); l<=A.l(3); l++)
127  {
128  A(i,j,k,l)=(i-A.f(0)+1)+(j-A.f(1)+1)*10
129  +(k-A.f(2)+1)*100+(l-A.f(3)+1)*1000;
130  }
131  }
132  }
133  }
134  CODE( dump_array(A,3); );
135  CODE( dump_array(A,2); );
136  CODE( dump_array(A,1); );
137  CODE( dump_array(A,0); );
138  DUMP( A.representation() );
139  }
140 
141  /*----------------------------------------------------------------------*/
142 
143  section("Test copy", '=');
144  section("non-const copy");
145  {
146  CODE( Array<float> A(3,4); );
147  CODE( Array<float> B(A); );
148  CODE( Array<float> C; );
149  CODE( C=B; );
150  CODE( A=15.5; );
151  CODE( A(2,3)=-2.; );
152  CODE( A(3,1)=-5.; );
153  CODE( dump_array(C); );
154  }
155  section("const copy");
156  {
157  CODE( Array<float> A(3,4); );
158  CODE( A=15.5; );
159  CODE( ConstArray<float> B(A); );
160  CODE( dump_array(B); );
161  CODE( A(2,3)=-2.; );
162  CODE( A(3,1)=-5.; );
164  CODE( H=A.representation(); );
165  CODE( H[5]=-12.; );
166  CODE( dump_array(B); );
168  CODE( H2=B.representation(); );
169  DUMP( H2 );
170 
171 #ifdef ILLEGAL1
172 #warning compiling supposedly illegal code
173  CODE( Array<float> C(B); );
174 #endif
175 
176 #ifdef ILLEGAL2
177 #warning compiling supposedly illegal code
178  CODE( Array<float> C; );
179  CODE( C=B; );
180 #endif
181 
182 #ifdef ILLEGAL3
183 #warning compiling supposedly illegal code
184  CODE( B(1,2)=12.; );
185 #endif
186 
187 #ifdef ILLEGAL4
188 #warning compiling supposedly illegal code
189  CODE( B=12.; );
190 #endif
191 
192 #ifdef ILLEGAL5
193 #warning compiling supposedly illegal code
194  CODE( H=B; );
195 #endif
196 
197 #ifdef ILLEGAL6
198 #warning compiling supposedly illegal code
199  CODE( H2[5]=-12.; );
200 #endif
201  }
202 
203  section("read access to ConstArray and const Array");
204  {
205  CODE( Array<int> A(3,3) );
206  CODE( ConstArray<int> B(A) );
207  CODE( const Array<int> C(A) );
208  CODE( A=123 );
209  CODE( cout << A(2,2) << ", " << B(2,2) << ", " << C(2,2) << endl );
210 
211 #ifdef ILLEGAL7
212 #warning compiling supposedly illegal code
213  CODE( C(1,1)=12; );
214 #endif
215  }
216 
217  section("test copyout function");
218  {
219  CODE( Array<int> A(8,8));
220  section("fill array");
221  for(int i=A.f(0); i<=A.l(0); i++)
222  {
223  for(int j=A.f(1); j<=A.l(1); j++)
224  {
225  A(i,j)=(i-A.f(0)+1)+(j-A.f(1)+1)*10;
226  }
227  }
228  CODE( dump_array(A); );
229  CODE( ConstArray<int> CA(subarray(A)(4,6)(3,5)));
230  CODE( dump_array(CA); );
231  CODE( Array<int> B=CA.copyout());
232  CODE( dump_array(B); );
233  }
234 }
Array< T > copyout() const
create an identical copy (deep copy) of this array
Definition: array.h:559
void section(const char *s, const char l='-')
print headline
Definition: arraytest.cc:75
#define DUMP(A)
Dump any object through its dump function.
Definition: dump_macros.h:62
#define AFF_ARRAYTEST_CC_VERSION
Definition: arraytest.cc:58
aff::util::Subarray< C > subarray(const C &c)
Wrapper function to select correct type.
Definition: subarray.h:163
A template class to share heap memory for different array projections.
Definition: sharedheap.h:252
#define CODE(C)
Dump code and execute (works like echo)
Definition: dump_macros.h:82
void dump_array(const ConstArray< T > &array, const Tdim &i=(Strided::Mmax_dimen-1), std::ostream &os=std::cout)
Dump array values.
Definition: dump_array.h:157
This is the base class for const elements.
Definition: sharedheap.h:139
Full multi-dimensional array functionality.This is the full array class template. It adds no addition...
Definition: array.h:151
Shaper class for Fortran layout.
Definition: shaper.h:66
Array base classThis is a multidimensional (array) container that uses a strided memory layout (Fortr...
Definition: array.h:172
Here is the call graph for this function: