"Fossies" - the Fresh Open Source Software Archive

Member "gama-2.05/tests/matvec/matvec-basic.cpp" (10 May 2019, 2254 Bytes) of package /linux/privat/gama-2.05.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "matvec-basic.cpp": 2.03_vs_2.04.

    1 /*
    2   GNU Gama C++ library tests/matvec
    3   Copyright (C) 2017, 2019  Ales Cepek <cepek@gnu.org>
    4 
    5   This file is part of the GNU Gama C++ library tests/matvec
    6   
    7   GNU Gama is free software: you can redistribute it and/or modify
    8   it under the terms of the GNU General Public License as published by
    9   the Free Software Foundation, either version 3 of the License, or
   10   (at your option) any later version.
   11   
   12   GNU Gama is distributed in the hope that it will be useful,
   13   but WITHOUT ANY WARRANTY; without even the implied warranty of
   14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15   GNU General Public License for more details.
   16 
   17   You should have received a copy of the GNU General Public License
   18   along with GNU Gama.  If not, see <http://www.gnu.org/licenses/>.
   19 */
   20 
   21 #include <matvec/matvec.h>
   22 #include <matvec/svd.h>
   23 #include <iostream>
   24 #include <string>
   25 
   26 using namespace GNU_gama;
   27 
   28 int b01()
   29 {
   30   double ver = std::stod(std::string(matvec_version()));
   31 
   32   Vec<> a, b{ {1,2,3,4,5,6,7,8,9,10} };
   33   Vec<>::size_type bd = b.dim();
   34 
   35   a = std::move(b);
   36   std::cout << "01# matvec_version() " << matvec_version() << " --> "
   37             << " a.dim() b.dim() : " << a.dim() << " " << b.dim() << "\n";
   38 
   39   if (ver >= 2.0)
   40     {
   41       // move constructor
   42       if (a.dim() != bd || b.dim() != 0 ) return 1;
   43       for (unsigned i=1; i<=bd; i++)
   44         if (a(i) != i) return 1;
   45     }
   46   else
   47     {
   48       // fall back to copy constructor
   49       if (a.dim() != bd || b.dim() != bd) return 1;
   50       for (unsigned i=1; i<=bd; i++)
   51         if (a(i) != i || a(i) != b(i)) return 1;
   52     }
   53 
   54   return 0;
   55 }
   56 
   57 
   58 int b02()
   59 {
   60   int result = 0;
   61 
   62   using std::cout;
   63   using std::endl;
   64 
   65   // code fragment from matvec_demo_001
   66 
   67   Mat<> A(5, 3);
   68   Vec<> b(5);
   69 
   70   try    // List initialisation for Mat<> and Vec<> --> move assignment
   71     {
   72        A = {{1.001, 0.006, 0.012},
   73             {0.002, 1.007, 0.013},
   74             {0.003, 0.008, 1.014},
   75             {1.004, 0.009, 1.015},
   76             {0.005, 1.011, 1.016}};
   77 
   78         b = {1.1, 1.9, 3.1, 4, 5.1};
   79     }
   80   catch (const Exception::matvec& e)
   81     {
   82       cout << e.description << endl;
   83       return 1;
   84     }
   85 
   86   return result;
   87 }
   88 
   89 
   90 int main()
   91 {
   92   int error = 0;
   93 
   94   error += b01();
   95   error += b02();
   96 
   97   return error;
   98 }