]> www.ginac.de Git - ginac.git/blob - check/check_matrices.cpp
- Added some tests from the Lewis-Wester testsuite.
[ginac.git] / check / check_matrices.cpp
1 /** @file check_matrices.cpp
2  *
3  *  Here we test manipulations on GiNaC's symbolic matrices. */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #include "checks.h"
24
25 // determinants of some sparse symbolic size x size matrices
26 static unsigned matrix_determinants(void)
27 {
28     unsigned result = 0;
29     symbol a("a");
30
31     for (int size=3; size<16; ++size) {
32         matrix A(size,size);
33         for (int c=0; c<size; ++c) {
34             for (int r=0;r<size-1; ++r)
35                 // populate 10 percent of the entries, the rest remains 0:
36                 if (!(int)(10.0*rand()/(RAND_MAX+1.0)))
37                     A.set(r,c,dense_univariate_poly(a,5));
38             // set the last line to a linear combination of two other lines
39             // to guarantee that the determinant vanishes:
40             A.set(size-1,c,A(0,c)-A(size-2,c));
41         }
42         if (!A.determinant().is_zero()) {
43             clog << "Determinant of " << size << "x" << size << " matrix "
44                  << endl << A << endl
45                  << "was not found to vanish!" << endl;
46             ++result;
47         }
48     }
49     
50     return result;
51 }
52
53 unsigned check_matrices(void)
54 {
55     unsigned result = 0;
56     
57     cout << "checking symbolic matrix manipulations" << flush;
58     clog << "---------symbolic matrix manipulations:" << endl;
59     
60     result += matrix_determinants();  cout << '.' << flush;
61     
62     if (!result) {
63         cout << " passed " << endl;
64         clog << "(no output)" << endl;
65     } else {
66         cout << " failed " << endl;
67     }
68     
69     return result;
70 }