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

◆ main()

int main ( )

test array functionality

Examples:
tests/arraytest.cc, tests/f77test.cc, tests/helpertest.cc, tests/operatortest.cc, tests/reprtest.cc, tests/seriestest.cc, tests/shapetest.cc, and tests/simplearraytest.cc.

Definition at line 153 of file arrayexample.cc.

References ARRAYEXAMPLE_VERSION, aff::Array< T >::copyout(), and section().

154 {
155  cout << ARRAYEXAMPLE_VERSION << endl;
156 
157  // create a 3x4 array of type float
158  aff::Array<float> A(3,4);
159 
160  // print array (layout and contents) to terminal
161  section("Array A after being created:");
162  cout << A;
163 
164  // set all elements in array to 5.2
165  A=5.2;
166  section("Array A after all elements being set to 5.2:");
167  cout << A;
168 
169  /* ---------------------------------------------------------------------- */
170 
171  section("Demonstrate effect of shallow copy", '=');
172  // create a second array
174 
175  // let B be a copy of A
176  B=A;
177 
178  // B just references the same memory; thus changing values in A and B will
179  // effectively change the same array values
180  A(2,3)=10.7;
181  B(3,1)=-19.3;
182 
183  // both modifications are present in A
184  section("Array A after assignment to B and to A:");
185  cout << A;
186 
187  /* ---------------------------------------------------------------------- */
188 
189  section("Demonstrate effect of deep copy", '=');
190  // create a copy by actually copying all elements
191  B=A.copyout();
192 
193  // modify B
194  B(3,3)=102.3;
195  section("Array B after assignment to B:");
196  cout << B;
197  section("Array A after assignment to B:");
198  cout << A;
199 
200  /* ---------------------------------------------------------------------- */
201 
202  section("Demonstrate array usage with custom index range", '=');
203 
204  /* To create an array which does not use index range beginning with 1, use
205  * the function Shaper, which is available through aff/shaper.h
206  */
207  A=aff::Array<float>(aff::Shaper(-2,6)(12,16));
208  A=sqrt(2.);
209  section("Array A after being assigned to array of different shape:");
210  cout << A;
211 }
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='-')
Definition: arrayexample.cc:82
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
#define ARRAYEXAMPLE_VERSION
Definition: arrayexample.cc:56
Here is the call graph for this function: