ARTS  2.2.66
test_matpack.cc
Go to the documentation of this file.
1 /* Copyright (C) 2001-2012 Stefan Buehler <sbuehler@ltu.se>
2 
3  This program is free software; you can redistribute it and/or modify it
4  under the terms of the GNU General Public License as published by the
5  Free Software Foundation; either version 2, or (at your option) any
6  later version.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16  USA. */
17 
18 #include <cmath>
19 #include <iostream>
20 #include <cstdlib>
21 #include "matpackVII.h"
22 #include "exceptions.h"
23 #include "array.h"
24 #include "make_array.h"
25 #include "mystring.h"
26 #include "make_vector.h"
27 #include "math_funcs.h"
28 #include "describe.h"
29 #include "matpackII.h"
30 #include "rational.h"
31 #include "logic.h"
32 #include "wigner_functions.h"
33 
34 using std::cout;
35 using std::endl;
36 using std::runtime_error;
37 
38 
40 {
41  return x+1;
42 }
43 
45 {
46  return x+1;
47 }
48 
50 {
51  x = 999;
52 }
53 
55 {
56  x = 888;
57 }
58 
59 int test1()
60 {
61  Vector v(20);
62 
63  cout << "v.nelem() = " << v.nelem() << "\n";
64 
65  for (Index i=0; i<v.nelem(); ++i )
66  v[i] = (Numeric)i;
67 
68  cout << "v.begin() = " << *v.begin() << "\n";
69 
70  cout << "v = \n" << v << "\n";
71 
72  fill_with_junk(v[Range(1,8,2)][Range(2,joker)]);
73  // fill_with_junk(v);
74 
75  Vector v2 = v[Range(2,4)];
76 
77  cout << "v2 = \n" << v2 << "\n";
78 
79  for (Index i=0 ; i<1000; ++i)
80  {
81  Vector v3(1000);
82  v3 = (Numeric)i;
83  }
84 
85  v2[Range(joker)] = 88;
86 
87  v2[Range(0,2)] = 77;
88 
89  cout << "v = \n" << v << "\n";
90  cout << "v2 = \n" << v2 << "\n";
91  cout << "v2.nelem() = \n" << v2.nelem() << "\n";
92 
93  Vector v3;
94  v3.resize(v2.nelem());
95  v3 = v2;
96 
97  cout << "\nv3 = \n" << v3 << "\n";
99  cout << "\nv3 after junking v2 = \n" << v3 << "\n";
100  v3 *= 2;
101  cout << "\nv3 after *2 = \n" << v3 << "\n";
102 
103  Matrix M(10,15);
104  {
105  Numeric n=0;
106  for (Index i=0; i<M.nrows(); ++i)
107  for (Index j=0; j<M.ncols(); ++j)
108  M(i,j) = ++n;
109  }
110 
111  cout << "\nM =\n" << M << "\n";
112 
113  cout << "\nM(Range(2,4),Range(2,4)) =\n" << M(Range(2,4),Range(2,4)) << "\n";
114 
115  cout << "\nM(Range(2,4),Range(2,4))(Range(1,2),Range(1,2)) =\n"
116  << M(Range(2,4),Range(2,4))(Range(1,2),Range(1,2)) << "\n";
117 
118  cout << "\nM(1,Range(joker)) =\n" << M(1,Range(joker)) << "\n";
119 
120  cout << "\nFilling M(1,Range(1,2)) with junk.\n";
121  fill_with_junk(M(1,Range(1,2)));
122 
123  cout << "\nM(Range(0,4),Range(0,4)) =\n" << M(Range(0,4),Range(0,4)) << "\n";
124 
125  cout << "\nFilling M(Range(4,2,2),Range(6,3)) with junk.\n";
126 
127  MatrixView s = M(Range(4,2,2),Range(6,3));
128  fill_with_junk(s);
129 
130  cout << "\nM =\n" << M << "\n";
131 
132  const Matrix C = M;
133 
134  cout << "\nC(Range(3,4,2),Range(2,3,3)) =\n"
135  << C(Range(3,4,2),Range(2,3,3)) << "\n";
136 
137  cout << "\nC(Range(3,4,2),Range(2,3,3)).transpose() =\n"
138  << transpose(C(Range(3,4,2),Range(2,3,3))) << "\n";
139 
140  return 0;
141 }
142 
143 void test2()
144 {
145  Vector v(50000000);
146 
147  cout << "v.nelem() = " << v.nelem() << "\n";
148 
149  cout << "Filling\n";
150 // for (Index i=0; i<v.nelem(); ++i )
151 // v[i] = sqrt(i);
152  v = 1.;
153  cout << "Done\n";
154 
155 }
156 
157 
158 void test4()
159 {
160  Vector a(10);
161  Vector b(a.nelem());
162 
163  for ( Index i=0; i<a.nelem(); ++i )
164  {
165  a[i] = (Numeric)(i+1);
166  b[i] = (Numeric)(a.nelem()-i);
167  }
168 
169  cout << "a = \n" << a << "\n";
170  cout << "b = \n" << b << "\n";
171  cout << "a*b \n= " << a*b << "\n";
172 
173  Matrix A(11,6);
174  Matrix B(10,20);
175  Matrix C(20,5);
176 
177  B = 2;
178  C = 3;
179  mult(A(Range(1,joker),Range(1,joker)),B,C);
180 
181  // cout << "\nB =\n" << B << "\n";
182  // cout << "\nC =\n" << C << "\n";
183  cout << "\nB*C =\n" << A << "\n";
184 
185 }
186 
187 void test5()
188 {
189  Vector a(10);
190  Vector b(20);
191  Matrix M(10,20);
192 
193  // Fill b and M with a constant number:
194  b = 1;
195  M = 2;
196 
197  cout << "b = \n" << b << "\n";
198  cout << "M =\n" << M << "\n";
199 
200  mult(a,M,b); // a = M*b
201  cout << "\na = M*b = \n" << a << "\n";
202 
203  mult(transpose((MatrixView)b),transpose((MatrixView)a),M); // b^t = a^t * M
204  cout << "\nb^t = a^t * M = \n" << transpose((MatrixView)b) << "\n";
205 
206 }
207 
208 void test6()
209 {
210  Index n = 5000;
211  Vector x(1,n,1), y(n);
212  Matrix M(n,n);
213  M = 1;
214  // cout << "x = \n" << x << "\n";
215 
216  cout << "Transforming.\n";
217  // transform(x,sin,x);
218  // transform(transpose(y),sin,transpose(x));
219  // cout << "sin(x) =\n" << y << "\n";
220  for (Index i=0; i<1000; ++i)
221  {
222  // mult(y,M,x);
223  transform(y,sin,static_cast<MatrixView>(x));
224  x+=1;
225  }
226  // cout << "y =\n" << y << "\n";
227 
228  cout << "Done.\n";
229 }
230 
231 void test7()
232 {
233  Vector x(1,20000000,1);
234  Vector y(x.nelem());
235  transform(y,sin,x);
236  cout << "min(sin(x)), max(sin(x)) = " << min(y) << ", " << max(y) << "\n";
237 }
238 
239 void test8()
240 {
241  Vector x(80000000);
242  for ( Index i=0; i<x.nelem(); ++i )
243  x[i] = (Numeric)i;
244  cout << "Done." << "\n";
245 }
246 
247 void test9()
248 {
249  // Initialization of Matrix with view of other Matrix:
250  Matrix A(4,8);
251  Matrix B(A(Range(joker),Range(0,3)));
252  cout << "B = " << B << "\n";
253 }
254 
255 void test10()
256 {
257  // Initialization of Matrix with a vector (giving a 1 column Matrix).
258 
259  // At the moment doing this with a non-const Vector will result in a
260  // warning message.
261  Vector v(1,8,1);
262  Matrix M((const Vector)v);
263  cout << "M = " << M << "\n";
264 }
265 
266 void test11()
267 {
268  // Assignment between Vector and Matrix:
269 
270  // At the moment doing this with a non-const Vector will result in a
271  // warning message.
272  Vector v(1,8,1);
273  Matrix M(v.nelem(),1);
274  M = v;
275  cout << "M = " << M << "\n";
276 }
277 
278 void test12()
279 {
280  // Copying of Arrays
281 
282  Array<String> sa(3);
283  sa[0] = "It's ";
284  sa[1] = "a ";
285  sa[2] = "test.";
286 
287  Array<String> sb(sa), sc(sa.nelem());
288 
289  cout << "sb = \n" << sb << "\n";
290 
291  sc = sa;
292 
293  cout << "sc = \n" << sc << "\n";
294 
295 }
296 
297 void test13()
298 {
299  // Mix vector and one-column matrix in += operator.
300  const Vector v(1,8,1); // The const is necessary here to
301  // avoid compiler warnings about
302  // different conversion paths.
303  Matrix M(v);
304  M += v;
305  cout << "M = \n" << M << "\n";
306 }
307 
308 void test14()
309 {
310  // Test explicit Array constructors.
311  Array<String> a = MakeArray<String>("Test");
313  Array<Numeric> c = MakeArray<Numeric>(1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0);
314  cout << "a = \n" << a << "\n";
315  cout << "b = \n" << b << "\n";
316  cout << "c = \n" << c << "\n";
317 }
318 
319 void test15()
320 {
321  // Test String.
322  String a = "Nur ein Test.";
323  cout << "a = " << a << "\n";
324  String b(a,5,-1);
325  cout << "b = " << b << "\n";
326 }
327 
328 /*void test16()
329 {
330  // Test interaction between Array<Numeric> and Vector.
331  Vector a;
332  Array<Numeric> b;
333  b.push_back(1);
334  b.push_back(2);
335  b.push_back(3);
336  a.resize(b.nelem());
337  a = b;
338  cout << "b =\n" << b << "\n";
339  cout << "a =\n" << a << "\n";
340 }*/
341 
342 void test17()
343 {
344  // Test Sum.
345  Vector a(1,10,1);
346  cout << "a.sum() = " << a.sum() << "\n";
347 }
348 
349 void test18()
350 {
351  // Test elementvise square of a vector:
352  Vector a(1,10,1);
353  a *= a;
354  cout << "a *= a =\n" << a << "\n";
355 }
356 
357 void test19()
358 {
359  // There exists no explicit filling constructor of the form
360  // Vector a(3,1.7).
361  // But you can use the more general filling constructor with 3 arguments.
362 
363  Vector a(1,10,1);
364  Vector b(5.3,10,0);
365  cout << "a =\n" << a << "\n";
366  cout << "b =\n" << b << "\n";
367 }
368 
369 void test20()
370 {
371  // Test MakeVector:
372  MakeVector a(1,2,3,4,5,6,7,8,9,10);
373  cout << "a =\n" << a << "\n";
374 }
375 
376 void test21()
377 {
378  Numeric s=0;
379  // Test speed of call by reference:
380  cout << "By reference:\n";
381  for ( Index i=0; i<1e8; ++i )
382  {
383  s += by_reference(s);
384  s -= by_reference(s);
385  }
386  cout << "s = " << s << "\n";
387 }
388 
389 void test22()
390 {
391  Numeric s=0;
392  // Test speed of call by value:
393  cout << "By value:\n";
394  for ( Index i=0; i<1e8; ++i )
395  {
396  s += by_value(s);
397  s -= by_value(s);
398  }
399  cout << "s = " << s << "\n";
400 }
401 
402 void test23()
403 {
404  // Test constructors that fills with constant:
405  Vector a(10,3.5);
406  cout << "a =\n" << a << "\n";
407  Matrix b(10,10,4.5);
408  cout << "b =\n" << b << "\n";
409 }
410 
411 void test24()
412 {
413  // Try element-vise multiplication of Matrix and Vector:
414  Matrix a(5,1,2.5);
415  Vector b(1,5,1);
416  a *= b;
417  cout << "a*=b =\n" << a << "\n";
418  a /= b;
419  cout << "a/=b =\n" << a << "\n";
420  a += b;
421  cout << "a+=b =\n" << a << "\n";
422  a -= b;
423  cout << "a-=b =\n" << a << "\n";
424 }
425 
426 void test25()
427 {
428  // Test min and max for Array:
429  MakeArray<Index> a(1,2,3,4,5,6,5,4,3,2,1);
430  cout << "min/max of a = " << min(a) << "/" << max(a) << "\n";
431 }
432 
433 void test26()
434 {
435  cout << "Test filling constructor for Array:\n";
436  Array<String> a(4,"Hello");
437  cout << "a =\n" << a << "\n";
438 }
439 
440 void test27()
441 {
442  cout << "Test Arrays of Vectors:\n";
443  Array<Vector> a;
444  a.push_back(MakeVector(1.0,2.0));
445  a.push_back(Vector(1.0,10,1.0));
446  cout << "a =\n" << a << "\n";
447 }
448 
449 void test28()
450 {
451  cout << "Test default constructor for Matrix:\n";
452  Matrix a;
453  Matrix b(a);
454  cout << "b =\n" << b << "\n";
455 }
456 
457 void test29()
458 {
459  cout << "Test Arrays of Matrix:\n";
460  ArrayOfMatrix a;
461  Matrix b;
462 
463  b.resize(2,2);
464  b(0,0) = 1;
465  b(0,1) = 2;
466  b(1,0) = 3;
467  b(1,1) = 4;
468  a.push_back(b);
469  b *= 2;
470  a.push_back(b);
471 
472  a[0].resize(2,3);
473  a[0] = 4;
474 
475  a.resize(3);
476  a[2].resize(4,5);
477  a[2] = 5;
478 
479  cout << "a =\n" << a << "\n";
480 }
481 
482 void test30()
483 {
484  cout << "Test Matrices of size 0:\n";
485  Matrix a(0,0);
486  // cout << "a(0,0) =\n" << a(0,0) << "\n";
487  a.resize(2,2);
488  a = 1;
489  cout << "a =\n" << a << "\n";
490 
491  Matrix b(3,0);
492  // cout << "b(0,0) =\n" << b(0,0) << "\n";
493  b.resize(b.nrows(),b.ncols()+3);
494  b = 2;
495  cout << "b =\n" << b << "\n";
496 
497  Matrix c(0,3);
498  // cout << "c(0,0) =\n" << c(0,0) << "\n";
499  c.resize(c.nrows()+3,c.ncols());
500  c = 3;
501  cout << "c =\n" << c << "\n";
502 }
503 
504 void test31()
505 {
506  cout << "Test Tensor3:\n";
507 
508  Tensor3 a(2,3,4,1.0);
509 
510  Index fill = 0;
511 
512  // Fill with some numbers
513  for ( Index i=0; i<a.npages(); ++i )
514  for ( Index j=0; j<a.nrows(); ++j )
515  for ( Index k=0; k<a.ncols(); ++k )
516  a(i,j,k) = (Numeric)(++fill);
517 
518  cout << "a =\n" << a << "\n";
519 
520  cout << "Taking out first row of first page:\n"
521  << a(0,0,Range(joker)) << "\n";
522 
523  cout << "Taking out last column of second page:\n"
524  << a(1,Range(joker),a.ncols()-1) << "\n";
525 
526  cout << "Taking out the first letter on every page:\n"
527  << a(Range(joker),0,0) << "\n";
528 
529  cout << "Taking out first page:\n"
530  << a(0,Range(joker),Range(joker)) << "\n";
531 
532  cout << "Taking out last row of all pages:\n"
533  << a(Range(joker),a.nrows()-1,Range(joker)) << "\n";
534 
535  cout << "Taking out second column of all pages:\n"
536  << a(Range(joker),Range(joker),1) << "\n";
537 
538  a *= 2;
539 
540  cout << "After element-vise multiplication with 2:\n"
541  << a << "\n";
542 
543  transform(a,sqrt,a);
544 
545  cout << "After taking the square-root:\n"
546  << a << "\n";
547 
548  Index s = 200;
549  cout << "Let's allocate a large tensor, "
550  << (Numeric)(s*s*s*8)/1024./1024.
551  << " MB...\n";
552 
553  a.resize(s,s,s);
554 
555  cout << "Set it to 1...\n";
556 
557  a = 1;
558 
559  cout << "a(900,900,900) = " << a(90,90,90) << "\n";
560 
561  fill = 0;
562 
563  cout << "Fill with running numbers, using for loops...\n";
564  for ( Index i=0; i<a.npages(); ++i )
565  for ( Index j=0; j<a.nrows(); ++j )
566  for ( Index k=0; k<a.ncols(); ++k )
567  a(i,j,k) = (Numeric)(++fill);
568 
569  cout << "Max(a) = ...\n";
570 
571  cout << max(a) << "\n";
572 
573 }
574 
575 void test32()
576 {
577  cout << "Test von X = A*X:\n";
578  Matrix X(3,3),A(3,3),B(3,3);
579 
580  for ( Index j=0; j<A.nrows(); ++j )
581  for ( Index k=0; k<A.ncols(); ++k )
582  {
583  X(j,k) = 1;
584  A(j,k) = (Numeric)(j+k);
585  }
586  cout << "A:\n" << A << "\n";
587  cout << "X:\n" << X << "\n";
588 
589  mult(B,A,X);
590  cout << "B = A*X:\n" << B << "\n";
591  mult(X,A,X);
592  cout << "X = A*X:\n" << X << "\n";
593 
594  cout << "This is not the same, and should not be, because you\n"
595  << "are not allowed to use the same matrix as input and output\n"
596  << "for mult!\n";
597 }
598 
599 void test33()
600 {
601  cout << "Making things look bigger than they are...\n";
602 
603  {
604  cout << "1. Make a scalar look like a vector:\n";
605  Numeric a = 3.1415; // Just any number here.
606  VectorView av(a);
607  cout << "a, viewed as a vector: " << av << "\n";
608  cout << "Describe a: " << describe(a) << "\n";
609  av[0] += 1;
610  cout << "a, after the first element\n"
611  << "of the vector has been increased by 1: " << a << "\n";
612  }
613 
614  {
615  cout << "\n2. Make a vector look like a matrix:\n"
616  << "This is an exception, because the new dimension is added at the end.\n";
617  MakeVector a(1,2,3,4,5);
618  MatrixView am = a;
619  cout << "a, viewed as a matrix:\n" << am << "\n";
620  cout << "Trasnpose view:\n" << transpose(am) << "\n";
621  cout << "Describe transpose(am): " << describe(transpose(am)) << "\n";
622 
623  cout << "\n3. Make a matrix look like a tensor3:\n";
624  Tensor3View at3 = am;
625  cout << "at3 = \n" << at3 << "\n";
626  cout << "Describe at3: " << describe(at3) << "\n";
627  at3 (0,2,0) += 1;
628  cout << "a after Increasing element at3(0,2,0) by 1: \n" << a << "\n\n";
629 
630  Tensor4View at4 = at3;
631  cout << "at4 = \n" << at4 << "\n";
632  cout << "Describe at4: " << describe(at4) << "\n";
633 
634  Tensor5View at5 = at4;
635  cout << "at5 = \n" << at5 << "\n";
636  cout << "Describe at5: " << describe(at5) << "\n";
637 
638  Tensor6View at6 = at5;
639  cout << "at6 = \n" << at6 << "\n";
640  cout << "Describe at6: " << describe(at6) << "\n";
641 
642  Tensor7View at7 = at6;
643  cout << "at7 = \n" << at7 << "\n";
644  cout << "Describe at7: " << describe(at7) << "\n";
645 
646  at7(0,0,0,0,0,2,0) -=1 ;
647 
648  cout << "After subtracting 1 from at7(0,0,0,0,0,2,0)\n"
649  << "a = " << a << "\n";
650 
651  cout << "\nAll in one go:\n";
652  Numeric b = 3.1415; // Just any number here.
653  Tensor7View bt7 =
654  Tensor6View(
655  Tensor5View(
656  Tensor4View(
657  Tensor3View(
658  MatrixView(
659  VectorView(b)
660  )
661  )
662  )
663  )
664  );
665  cout << "bt7:\n" << bt7 << "\n";
666  cout << "Describe bt7: " << describe(bt7) << "\n";
667  }
668 }
669 
671 {
672  cout << "Describe a: " << describe(a) << "\n";
673 }
674 
676 {
677  cout << "Describe a: " << describe(a) << "\n";
678 }
679 
680 void test34()
681 {
682  cout << "Test, if dimension expansion works implicitly.\n";
683 
684  Tensor3 t3(2,3,4);
685  junk4(t3);
686 
687  Numeric x;
689 }
690 
691 void test35()
692 {
693  cout << "Test the new copy semantics.\n";
694  Vector a(1,4,1);
695  Vector b;
696 
697  b = a;
698  cout << "b = " << b << "\n";
699 
700  Vector aa(1,5,1);
701  ConstVectorView c = aa;
702  b = c;
703  cout << "b = " << b << "\n";
704 
705  Vector aaa(1,6,1);
706  VectorView d = aaa;
707  b = d;
708  cout << "b = " << b << "\n";
709 }
710 
711 void test36()
712 {
713  cout << "Test using naked joker on Vector.\n";
714  Vector a(1,4,1);
715  VectorView b = a[joker];
716  cout << "a = " << a << "\n";
717  cout << "b = " << b << "\n";
718 }
719 
720 void test37(const Index& i)
721 {
722  Vector v1(5e-15, 10, 0.42e-15/11);
723  Vector v2=v1;
724  // Index i = 10000000;
725 
726  v1 /= (Numeric)i;
727  v2 /=(Numeric)i;
728  cout.precision(12);
729  // cout.setf(ios_base::scientific,ios_base::floatfield);
730  v1*=v1;
731  v2*=v2;
732 cout << v1 << endl;
733  cout << v2 << endl;
734 }
735 
736 void test38 ()
737 {
738  Vector v (5, 0.);
739  Numeric * const a = v.get_c_array();
740 
741  a[4] = 5.;
742 
743  cout << v << endl;
744  cout << endl << "========================" << endl << endl;
745 
746  Matrix m (5, 5, 0.);
747  Numeric * const b = m.get_c_array();
748 
749  b[4] = 5.;
750 
751  cout << m << endl;
752  cout << endl << "========================" << endl << endl;
753 
754  Tensor3 t3 (5, 6, 7, 0.);
755  Numeric * const c = t3.get_c_array();
756 
757  c[6] = 5.;
758 
759  cout << t3 << endl;
760 }
761 
762 void test39 ()
763 {
764  Vector v1(1,5,1),v2(5);
765 
766  v2 = v1 * 2;
767  // Unfortunately, this thing compiles, but at least it gives an
768  // assertion failure at runtime. I think what happens is that it
769  // implicitly creates a one element vector out of the "2", then
770  // tries to do a scalar product with v1.
771 
772  cout << v2 << endl;
773 
774 }
775 
776 void test40()
777 {
778  Vector v(100);
779 
780  v = 5;
781 
782  cout << v << endl;
783 }
784 
785 void test41()
786 {
787  const Vector v1(10, 1);
788 
789  ConstVectorView vv = v1[Range(0, 5)];
790 
791  cout << "Vector: " << v1 << endl;
792  cout << "VectorView: " << vv << endl;
793 
794  try {
795  vv = 2;
796  } catch (runtime_error e) {
797  std::cerr << e.what() << endl;
798  exit(EXIT_FAILURE);
799  }
800 
801  cout << "VectorView: " << vv << endl;
802  cout << "Vector: " << v1 << endl;
803 }
804 
805 // Test behaviour of VectorView::operator MatrixView, for which I have fixed
806 // a bug today.
807 // SAB 2013-01-18
808 void test42()
809 {
810  cout << "test42\n";
811  Vector x = MakeVector(1,2,3,4,5,6,7,8,9,10);
812  cout << "x: " << x << endl;
813 
814  VectorView y = x[Range(2,4,2)];
815  cout << "y: " << y << endl;
816 
817  ConstMatrixView z(y);
818  cout << "z:\n" << z << endl;
819 
820  cout << "Every other z:\n" << z(Range(1,2,2),joker) << endl;
821 
822  // Try write access also:
823  MatrixView zz(y);
824  zz(Range(1,2,2),joker) = 0;
825  cout << "zz:\n" << zz << endl;
826  cout << "New x: " << x << endl;
827 }
828 
829 
830 void test43()
831 {
832  Rational r(3,2);
833  Rational r2;
834  r2 = 1;
835  cout << r2+r << endl;
836  cout << 1+r << endl;
837  cout << r+1 << endl;
838 }
839 
840 
841 void test44()
842 {
843 #define docheck(fn, val, expect) \
844  cout << #fn << "(" << val << ") = " << fn(x) << " (expected " << #expect << ")" << std::endl;
845 
846  Vector x = MakeVector(1, 2, 3);
847  docheck(is_increasing, x, 1)
848  docheck(is_decreasing, x, 0)
849  docheck(is_sorted, x, 1)
850 
851  x = MakeVector(3, 2, 1);
852  docheck(is_increasing, x, 0)
853  docheck(is_decreasing, x, 1)
854  docheck(is_sorted, x, 0)
855 
856  x = MakeVector(1, 2, 2);
857  docheck(is_increasing, x, 0)
858  docheck(is_decreasing, x, 0)
859  docheck(is_sorted, x, 1)
860 
861  x = MakeVector(2, 2, 1);
862  docheck(is_increasing, x, 0)
863  docheck(is_decreasing, x, 0)
864  docheck(is_sorted, x, 0)
865 
866  x = MakeVector(1, NAN, 2);
867  docheck(is_increasing, x, 0)
868  docheck(is_decreasing, x, 0)
869  docheck(is_sorted, x, 0)
870 
871  x = MakeVector(2, NAN, 1);
872  docheck(is_increasing, x, 0)
873  docheck(is_decreasing, x, 0)
874  docheck(is_sorted, x, 0)
875 
876  x = MakeVector(NAN, NAN, NAN);
877  docheck(is_increasing, x, 0)
878  docheck(is_decreasing, x, 0)
879  docheck(is_sorted, x, 0)
880 
881 #undef docheck
882 }
883 
884 
885 void test45()
886 {
887  //Rational j1=1,j2=1,j3=1,m1=0,m2=0,m3=0;
888  //std::cout << "My function " << wigner3j(j1,j2,j3,m1,m2,m3) << std::endl;
889 /*
890  ArrayOfIndex a,b;
891  a=MakeArray<Index>(1,4,5);b=MakeArray<Index>(20,10,10);
892  std::cout << "My factorials for nominators ["<<a<<" ] and denominators ["<<b<<" ]: " << factorials(a,b) <<"." << std::endl;*/
893 
894 /*
895  for(Rational L(1);L<3;L++)
896  {
897  std::cout << "L="<<L<<std::endl;
898  for(Rational ii=1;ii<11;ii++)
899  {
900  for(Rational jj=1;jj<11;jj++)
901  {
902  std::cout << " "<< wigner3j(ii,jj,L,0,0,0);
903  }
904  std::cout << std::endl;
905  }
906  std::cout << std::endl;
907  }*/
908 std::cout<<pow(0,0.3)<<std::endl;
909 ArrayOfIndex N;N=MakeArray<Index>(1, 1, 3, 3, 5, 5, 7, 7, 9, 9, 11, 11, 13, 13, 15, 15, 17, 17, 19, 19, 21, 21, 23, 23, 25, 25, 27, 27, 29, 29,
910  31, 31, 33, 33, 35, 35, 37, 37);
911 ArrayOfIndex J;J=MakeArray<Index>(0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14, 16, 16, 18, 18, 20, 20, 22, 22, 24, 24, 26, 26, 28, 28, 30,
912  30, 32, 32, 34, 34, 36, 36, 38);
913 
914  for(Index II = 0; II<N.nelem(); II++)
915  {
916  for(Index JJ = 0; JJ<N.nelem(); JJ++)
917  {
918  const Rational Nl(N[II]),Nk(N[JJ]);
919  Numeric A=0;
920  for(Index L(0);L<=10*max(J);L++)
921  {
922  //if(l<k)
923  {
924  A+=
925  sqrt(2*Nk.toNumeric()+1)*
926  sqrt(2*Nl.toNumeric()+1)*
927  sqrt(sqrt(2*Nk.toNumeric()+1)*
928  sqrt(2*Nl.toNumeric()+1)*
929  sqrt(2*J[II]+1)*
930  sqrt(2*J[JJ]+1))*
931  ECS_wigner(L,Nl,Nk,Nk,Nl,J[II],J[JJ])*
932  pow(-1., (Nk+Nl+L+1).toNumeric());
933  }
934  }
935  std::cout << " " << A;
936  }
937  std::cout << std::endl;
938  }
939 
940  Vector d; d.resize(38);
941 
942  for(Index II = 0; II<N.nelem(); II++)
943  d[II] = wigner6j(1, 1, 1, J[II], N[II], N[II]) * pow(-1.,2.*(Numeric)N[II]) * sqrt(6*(2*N[II]+1)*(2*J[II]+1));
944 
945  std::cout<<d<<std::endl;
946 
947 // for(Index a = 1; a<6; a++)
948 // for(Index b = 1; b<6; b++)
949 // for(Index c = 1; c<6; c++)
950 // std::cout << wigner3j(a,b,c,0,0,0)<<std::endl;
951 
952 }
953 
954 int main()
955 {
956 // test1();
957 // test2();
958 // test3();
959 // test4();
960 // test5();
961 // test6();
962 // test7();
963 // test8();
964 // test9();
965 // test10();
966 // test11();
967 // test12();
968 // test13();
969 // test14();
970 // test15();
971 // test16();
972 // test17();
973 // test18();
974 // test19();
975 // test20();
976 // test21();
977 // test22();
978 // test23();
979 // test24();
980 // test25();
981 // test26();
982 // test27();
983 // test28();
984 // test29();
985 // test30();
986 // test31();
987 // test32();
988 // test33();
989 // test34();
990 // test35();
991 // test36();
992 // Index i = 10000000;
993 // test37(i);
994 // test38();
995 // test39();
996 // test40();
997 // test41();
998 // test42();
999 // test43();
1000 // test44();
1001  test45();
1002 
1003  return 0;
1004 }
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:35
void test12()
void test21()
#define N
Definition: rng.cc:195
The VectorView class.
Definition: matpackI.h:372
void junk2(ConstVectorView a)
The Tensor4View class.
Definition: matpackIV.h:243
#define C(a, b)
Definition: Faddeeva.cc:254
ConstMatrixView transpose(ConstMatrixView m)
Const version of transpose.
Definition: matpackI.cc:1799
void test15()
#define M
Definition: rng.cc:196
Index nelem() const
Number of elements.
Definition: array.h:176
void test26()
Explicit construction of Arrays.
Definition: make_array.h:51
void test28()
void test17()
The Tensor7View class.
Definition: matpackVII.h:780
String describe(ConstTensor7View x)
Describe Tensor7.
Definition: describe.cc:39
const Numeric * get_c_array() const
Conversion to plain C-array.
Definition: matpackI.cc:1214
The Vector class.
Definition: matpackI.h:556
The MatrixView class.
Definition: matpackI.h:679
Header file for describe.cc.
void test11()
bool is_increasing(ConstVectorView x)
Checks if a vector is sorted and strictly increasing.
Definition: logic.cc:275
The range class.
Definition: matpackI.h:148
int test1()
Definition: test_matpack.cc:59
void test43()
void test44()
The Tensor6View class.
Definition: matpackVI.h:449
void test41()
ConstIterator1D begin() const
Return const iterator to first element.
Definition: matpackI.cc:346
void test7()
Numeric wigner6j(const Rational j1, const Rational j2, const Rational j3, const Rational J1, const Rational J2, const Rational J3)
void test10()
void test34()
void fill_with_junk(VectorView x)
Definition: test_matpack.cc:49
void test24()
Index nrows() const
Returns the number of rows.
Definition: matpackIII.h:146
void test42()
Index nelem() const
Returns the number of elements.
Definition: matpackI.cc:180
void test38()
void test4()
This file contains the definition of Array.
void test25()
void mult(VectorView y, const ConstMatrixView &M, const ConstVectorView &x)
Matrix Vector multiplication.
Definition: matpackI.cc:1648
void test14()
Index ncols() const
Returns the number of columns.
Definition: matpackI.cc:838
const Numeric * get_c_array() const
Conversion to plain C-array.
Definition: matpackI.cc:542
int main()
The Tensor3 class.
Definition: matpackIII.h:348
Numeric by_value(Numeric x)
Definition: test_matpack.cc:44
Header file for sparse matrices.
void test27()
Numeric toNumeric() const
Definition: rational.h:52
bool is_sorted(ConstVectorView x)
Checks if a vector is sorted in ascending order.
Definition: logic.cc:253
Index ncols() const
Returns the number of columns.
Definition: matpackIII.h:149
Numeric by_reference(const Numeric &x)
Definition: test_matpack.cc:39
Numeric sum() const
The sum of all elements of a Vector.
Definition: matpackI.cc:186
The Tensor3View class.
Definition: matpackIII.h:232
void test40()
#define max(a, b)
Definition: continua.cc:20461
void junk4(Tensor4View a)
The declarations of all the exception classes.
void test8()
void test23()
void test45()
const Joker joker
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:29
void test19()
The Matrix class.
Definition: matpackI.h:788
Implements the class MakeArray, which is a derived class of Array, allowing explicit initialization...
#define docheck(fn, val, expect)
void test33()
void test30()
void test20()
void test13()
void test35()
void test32()
The Tensor5View class.
Definition: matpackV.h:276
Header file for logic.cc.
Index npages() const
Returns the number of pages.
Definition: matpackIII.h:143
void test22()
void test5()
The class MakeVector is a special kind of Vector that can be initialized explicitly from one or more ...
void resize(Index n)
Assignment operator from VectorView.
Definition: matpackI.cc:798
#define min(a, b)
Definition: continua.cc:20460
A constant view of a Vector.
Definition: matpackI.h:292
void test31()
void test37(const Index &i)
Contains the rational class definition.
A constant view of a Matrix.
Definition: matpackI.h:596
void transform(VectorView y, double(&my_func)(double), ConstVectorView x)
A generic transform function for vectors, which can be used to implement mathematical functions opera...
Definition: matpackI.cc:1838
void test29()
Numeric ECS_wigner(Rational L, Rational Nl, Rational Nk, Rational Jk_lower, Rational Jl_lower, Rational Jk_upper, Rational Jl_upper)
bool is_decreasing(ConstVectorView x)
Checks if a vector is sorted in reversed order and is strictly decreasing.
Definition: logic.cc:324
void test36()
const Numeric * get_c_array() const
Conversion to plain C-array.
Definition: matpackIII.cc:455
void test18()
void test39()
void test2()
Index nrows() const
Returns the number of rows.
Definition: matpackI.cc:832
This file contains the definition of String, the ARTS string class.
void resize(Index r, Index c)
Resize function.
Definition: matpackI.cc:1580
void test6()
void test9()