Debian Codegraph @

examples/matmul.C

raw
1 /* Copyright (c) FFLAS-FFPACK
2 * ========LICENCE========
3 * This file is part of the library FFLAS-FFPACK.
4 *
5 * FFLAS-FFPACK is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 * ========LICENCE========
19 */
20
21 #include <iostream>
22
23 #include "fflas-ffpack/fflas-ffpack.h"
24
25 /**
26 * This example computes the matrix multiplication
27 * over a defined finite field.
28 *
29 * Outputs the product of the matrix given as input.
30 */
31 int main(int argc, char** argv)
32 {
33 if (argc != 4) {
34 std::cerr << "Usage: matmul <p> <matrixA> <matrixB>" << std::endl;
35 return -1;
36 }
37
38 int p = atoi(argv[1]);
39 std::string fileA = argv[2];
40 std::string fileB = argv[3];
41
42 // Creating the finite field Z/pZ (assuming p>2, use Modular<float> for p=2)
43 Givaro::ModularBalanced<double> F(p);
44
45 // Reading the matrices
46 double* A, *B, *C;
47 size_t mA, nA, mB, nB;
48 FFLAS::ReadMatrix(fileA.c_str(), F, mA, nA, A);
49 FFLAS::ReadMatrix(fileB.c_str(), F, mB, nB, B);
50 C = FFLAS::fflas_new(F, mA, nB);
51
52 if (nA != mB) {
53 std::cerr << "Those matrices can't be multiplied together" << std::endl;
54 return -1;
55 }
56
57 FFLAS::fgemm(F, FFLAS::FflasNoTrans, FFLAS::FflasNoTrans, mA, nB, nA,
58 F.one, A, mA, B, mB, F.zero, C, mA);
59
60 FFLAS::WriteMatrix(std::cout << "Result" << std::endl, F, mA, nB, C, mA) << std::endl;
61
62 FFLAS::fflas_delete(A);
63 FFLAS::fflas_delete(B);
64 FFLAS::fflas_delete(C);
65
66 return 0;
67 }
68 /* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
69 // vim:sts=4:sw=4:ts=4:et:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s