|
| 1 | +/* |
| 2 | + * examples/ratdet.C |
| 3 | + * |
| 4 | + * Copyright (C) 2020 The LinBox group |
| 5 | + * ========LICENCE======== |
| 6 | + * This file is part of the library LinBox. |
| 7 | + * |
| 8 | + * LinBox is free software: you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU Lesser General Public |
| 10 | + * License as published by the Free Software Foundation; either |
| 11 | + * version 2.1 of the License, or (at your option) any later version. |
| 12 | + * |
| 13 | + * This library 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 GNU |
| 16 | + * Lesser General Public License for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU Lesser General Public |
| 19 | + * License along with this library; if not, write to the Free Software |
| 20 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 | + * ========LICENCE======== |
| 22 | + */ |
| 23 | + |
| 24 | +/**\file examples/ratdet.C |
| 25 | + * @example examples/ratdet.C |
| 26 | + \brief Determinant of rational matrix |
| 27 | + \ingroup examples |
| 28 | + */ |
| 29 | + |
| 30 | +#include <linbox/linbox-config.h> |
| 31 | +#include <iostream> |
| 32 | + |
| 33 | +#include <givaro/givrational.h> |
| 34 | +#include <linbox/matrix/sparse-matrix.h> |
| 35 | +#include <linbox/solutions/det.h> |
| 36 | + |
| 37 | +using namespace LinBox; |
| 38 | +typedef SparseMatrixFormat::SparseSeq SparseStorage; |
| 39 | +typedef Givaro::QField<Givaro::Rational> Rationals; |
| 40 | + |
| 41 | +template<typename RMatrix> |
| 42 | +int ratdet(int argc, char **argv) { |
| 43 | + |
| 44 | + std::ifstream input (argv[1]); |
| 45 | + if (!input) { |
| 46 | + std::cerr << "Error opening matrix file: " << argv[1] << std::endl; |
| 47 | + return -1; |
| 48 | + } |
| 49 | + |
| 50 | + Rationals QQ; |
| 51 | + MatrixStream<Rationals> ms (QQ, input); |
| 52 | + RMatrix A ( ms ); |
| 53 | + |
| 54 | + Rationals::Element det_A; |
| 55 | + |
| 56 | + LinBox::Timer tim ; tim.clear() ; tim.start(); |
| 57 | + det (det_A, A); |
| 58 | + tim.stop(); |
| 59 | + |
| 60 | + std::cout << "Determinant is "; |
| 61 | + QQ.write(std::cout, det_A) << ':' << std::flush; |
| 62 | + std::clog << tim << std::endl; |
| 63 | + |
| 64 | + return 0; |
| 65 | +} |
| 66 | + |
| 67 | + |
| 68 | +int main (int argc, char **argv) |
| 69 | +{ |
| 70 | + commentator().setMaxDetailLevel (-1); |
| 71 | + commentator().setMaxDepth (-1); |
| 72 | + commentator().setReportStream (std::cerr); |
| 73 | + |
| 74 | + bool dense=true; |
| 75 | + if (argc < 2 || argc > 3) { |
| 76 | + std::cerr << "Usage: ratdet <matrix-file-in-supported-format> [d/s]" << std::endl; |
| 77 | + return -1; |
| 78 | + } |
| 79 | + |
| 80 | + if (argc == 3) { |
| 81 | + if (argv[2][0] != 'd') dense=false; |
| 82 | + } |
| 83 | + |
| 84 | + if (dense) |
| 85 | + return ratdet< DenseMatrix<Rationals> >(argc,argv); |
| 86 | + else |
| 87 | + return ratdet< SparseMatrix<Rationals, SparseStorage> >(argc, argv); |
| 88 | +} |
| 89 | + |
| 90 | +// Local Variables: |
| 91 | +// mode: C++ |
| 92 | +// tab-width: 4 |
| 93 | +// indent-tabs-mode: nil |
| 94 | +// c-basic-offset: 4 |
| 95 | +// End: |
| 96 | +// vim:sts=4:sw=4:ts=4:et:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s |
0 commit comments