]> www.ginac.de Git - ginac.git/blob - check/time_lw_IJKL.cpp
Make new tinfo-system work on AMD64.
[ginac.git] / check / time_lw_IJKL.cpp
1 /** @file time_lw_IJKL.cpp
2  *
3  *  Tests I, J, K and L from the paper "Comparison of Polynomial-Oriented CAS"
4  *  by Robert H. Lewis and Michael Wester. */
5
6 /*
7  *  GiNaC Copyright (C) 1999-2005 Johannes Gutenberg University Mainz, Germany
8  *
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 2 of the License, or
12  *  (at your option) any later version.
13  *
14  *  This program is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, write to the Free Software
21  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22  */
23
24 #include "times.h"
25
26 static unsigned test(unsigned n)
27 {
28         unsigned result = 0;
29         timer cartier;
30         char name = (n==40?'I':(n==70?'K':'?'));
31         
32         cout << "timing Lewis-Wester test " << name
33              << " (invert rank " << n << " Hilbert)" << flush;
34         clog << "-------Lewis-Wester test " << name
35              << " (invert rank " << n << " Hilbert):" << endl;
36         
37         // Create a rank n Hilbert matrix:
38         matrix H(n,n);
39         for (unsigned r=0; r<n; ++r)
40                 for (unsigned c=0; c<n; ++c)
41                         H.set(r,c,numeric(1,r+c+1));
42         // invert it:
43         cartier.start();
44         matrix Hinv(n,n);
45         Hinv = H.inverse();
46         cout << ". passed ";
47         clog << "(no output)" << endl;
48         cout << cartier.read() << 's' << endl;
49         
50         // check result:
51         name = (n==40?'J':(n==70?'L':'?'));
52         
53         cout << "timing Lewis-Wester test " << name
54              << " (check rank " << n << " Hilbert)" << flush;
55         clog << "-------Lewis-Wester test " << name
56              << " (check rank " << n << " Hilbert):" << endl;
57         
58         cartier.reset();
59         matrix identity = H.mul(Hinv);
60         bool correct = true;
61         for (unsigned r=0; r<n; ++r)
62                 for (unsigned c=0; c<n; ++c) {
63                         if (r==c) {
64                                 if (identity(r,c)!=1)
65                                         correct = false;
66                         } else {
67                                 if (identity(r,c)!=0)
68                                         correct = false;
69                         }
70                 }
71         if (correct) {
72                 cout << ". passed ";
73                 clog << "(no output)" << endl;
74         } else {
75                 cout << ". failed ";
76                 ++result;
77         }
78         cout << cartier.read() << 's' << endl;
79         return result;
80 }
81
82 unsigned time_lw_IJKL()
83 {
84         unsigned result = 0;
85         
86         // Tests I and J:
87         result += test(40);
88         // Tests K and L:
89         result += test(70);
90         
91         return result;
92 }