1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
/*
* examples/smithvalence.C
* Copyright (c) Linbox
* ========LICENCE========
* This file is part of the library LinBox.
*
* LinBox is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* ========LICENCE========
*/
/**\file examples/smithvalence.C
* @example examples/smithvalence.C
\brief Valence of sparse matrix over Z or Zp.
\ingroup examples
*/
#ifndef DISABLE_COMMENTATOR
#define DISABLE_COMMENTATOR
#endif
#define __LB_VALENCE_REPORTING__ 1
#define __LB_CRA_REPORTING__ 1
#define __LB_CRA_TIMING__ 1
#include <linbox/linbox-config.h>
#include <iostream>
#include <givaro/givintfactor.h>
#include <fflas-ffpack/paladin/parallel.h>
#include <linbox/solutions/smith-form.h>
#include <linbox/algorithms/smith-form-valence.h>
#include <vector>
using namespace LinBox;
int main (int argc, char **argv)
{
if (argc < 2 || argc > 4) {
std::cerr << "Usage: smithvalence <matrix-file-in-supported-format> [-ata|-aat|valence] [coprime]" << std::endl;
std::cerr << " Optional parameters valence and coprime are integers." << std::endl;
std::cerr << " Prime factors of valence will be used for local computation." << std::endl;
std::cerr << " coprime will be used for overall Z rank computation." << std::endl;
return -1;
}
const std::string filename(argv[1]);
std::ifstream input (filename);
if (!input) { std::cerr << "Error opening matrix file " << filename << std::endl; return -1; }
Givaro::ZRing<Integer> ZZ;
MatrixStream< Givaro::ZRing<Integer> > ms( ZZ, input );
typedef SparseMatrix<Givaro::ZRing<Integer>> Blackbox;
Blackbox A (ms);
input.close();
std::clog << "A is " << A.rowdim() << " by " << A.coldim() << std::endl;
size_t method=0;
Givaro::Integer val_A(0);
if (argc >= 3) {
if (strcmp(argv[2],"-ata") == 0) {
method=2;
}
else if (strcmp(argv[2],"-aat") == 0) {
method=1;
}
else {
std::clog << "Suppose primes are contained in " << argv[2] << std::endl;
val_A = LinBox::Integer(argv[2]);
}
}
Givaro::Integer coprimeV=1;
if (argc >= 4) {
std::clog << "Suppose " << argv[3] << " is coprime with Smith form" << std::endl;
coprimeV =Givaro::Integer(argv[3]);
}
std::vector<Givaro::Integer> SmithDiagonal;
#ifdef __LINBOX_USE_OPENMP
std::clog << "num procs: " << omp_get_num_procs() << std::endl;
std::clog << "max threads: " << MAX_THREADS << std::endl;
#endif
// Returns the Smith form as a diagonal,
// the valence val_A,
// the coprimeV used to compute the integral rank
LinBox::Timer chrono; chrono.start();
PAR_BLOCK {
smithValence(SmithDiagonal, val_A, A, filename, coprimeV, method);
}
chrono.stop();
std::clog << "Integer Smith Form (" << SmithDiagonal.size() << "):" << std::endl;
writeCompressedSmith(std::cout, SmithDiagonal, ZZ, A.rowdim(), A.coldim()) << std::endl;
std::clog << chrono << std::endl;
return 0;
}
// Local Variables:
// mode: C++
// tab-width: 4
// indent-tabs-mode: nil
// c-basic-offset: 4
// End:
// vim:sts=4:sw=4:ts=4:et:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s
|