]> www.ginac.de Git - ginac.git/blobdiff - check/check_lsolve.cpp
Finalize 1.7.6 release.
[ginac.git] / check / check_lsolve.cpp
index 02a1df5c18072458d28be436fe58c99f92f8df94..d09b6e9dda94fe7b30703256480bb9f1ad8dd753 100644 (file)
@@ -5,7 +5,7 @@
  *  the underlying symbolic manipulations. */
 
 /*
- *  GiNaC Copyright (C) 1999-2007 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2019 Johannes Gutenberg University Mainz, Germany
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include "checks.h"
+#include "ginac.h"
+using namespace GiNaC;
+
+#include <cstdlib> // for rand()
+#include <iostream>
 #include <sstream>
+using namespace std;
+
+extern const ex 
+dense_univariate_poly(const symbol & x, unsigned degree);
 
 static unsigned check_matrix_solve(unsigned m, unsigned n, unsigned p,
                                                                   unsigned degree)
@@ -110,7 +118,6 @@ static unsigned check_inifcns_lsolve(unsigned n)
                }
                lst eqns;  // equation list
                lst vars;  // variable list
-               ex sol; // solution
                // Create a random linear system...
                for (unsigned i=0; i<n; ++i) {
                        ex lhs = rand()%201-100;
@@ -123,32 +130,34 @@ static unsigned check_inifcns_lsolve(unsigned n)
                        eqns.append(lhs==rhs);
                        vars.append(x[i]);
                }
-               // ...solve it...
-               sol = lsolve(eqns, vars);
-               
-               // ...and check the solution:
-               if (sol.nops() == 0) {
-                       // no solution was found
-                       // is the coefficient matrix really, really, really degenerate?
-                       matrix coeffmat(n,n);
-                       for (unsigned ro=0; ro<n; ++ro)
-                               for (unsigned co=0; co<n; ++co)
-                                       coeffmat.set(ro,co,eqns.op(co).rhs().coeff(a[co],1));
-                       if (!coeffmat.determinant().is_zero()) {
-                               ++result;
-                               clog << "solution of the system " << eqns << " for " << vars
-                                        << " was not found" << endl;
-                       }
-               } else {
-                       // insert the solution into rhs of out equations
-                       bool errorflag = false;
-                       for (unsigned i=0; i<n; ++i)
-                               if (eqns.op(i).rhs().subs(sol) != eqns.op(i).lhs())
-                                       errorflag = true;
-                       if (errorflag) {
-                               ++result;
-                               clog << "solution of the system " << eqns << " for " << vars
-                                    << " erroneously returned " << sol << endl;
+               // ...solve it with each algorithm...
+               for (int algo = solve_algo::automatic; algo <= solve_algo::markowitz; algo++) {
+                       ex sol = lsolve(eqns, vars, algo);
+                       // ...and check the solution:
+                       if (sol.nops() == 0) {
+                               // no solution was found
+                               // is the coefficient matrix really, really, really degenerate?
+                               matrix coeffmat(n,n);
+                               for (unsigned ro=0; ro<n; ++ro)
+                                       for (unsigned co=0; co<n; ++co)
+                                               coeffmat.set(ro,co,eqns.op(co).rhs().coeff(a[co],1));
+                               if (!coeffmat.determinant().is_zero()) {
+                                       ++result;
+                                       clog << "solution of the system " << eqns << " for " << vars
+                                            << " was not found using algorithm " << algo << endl;
+                               }
+                       } else {
+                               // insert the solution into rhs of out equations
+                               bool errorflag = false;
+                               for (unsigned i=0; i<n; ++i)
+                                       if (eqns.op(i).rhs().subs(sol) != eqns.op(i).lhs())
+                                               errorflag = true;
+                               if (errorflag) {
+                                       ++result;
+                                       clog << "solution of the system " << eqns << " for " << vars
+                                            << " erroneously returned " << sol << " using algorithm "
+                                            << algo << endl;
+                               }
                        }
                }
        }
@@ -161,7 +170,6 @@ unsigned check_lsolve()
        unsigned result = 0;
        
        cout << "checking linear solve" << flush;
-       clog << "---------linear solve:" << endl;
        
        // solve some numeric linear systems
        for (unsigned n=1; n<14; ++n)
@@ -191,12 +199,10 @@ unsigned check_lsolve()
        result += check_inifcns_lsolve(5);  cout << '.' << flush;
        result += check_inifcns_lsolve(6);  cout << '.' << flush;
                
-       if (!result) {
-               cout << " passed " << endl;
-               clog << "(no output)" << endl;
-       } else {
-               cout << " failed " << endl;
-       }
-       
        return result;
 }
+
+int main(int argc, char** argv)
+{
+       return check_lsolve();
+}