File: sparse_view_test.cpp

package info (click to toggle)
boost1.90 1.90.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 593,168 kB
  • sloc: cpp: 4,190,642; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,776; makefile: 1,162; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (106 lines) | stat: -rw-r--r-- 3,028 bytes parent folder | download | duplicates (17)
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
//  Copyright (c) 2009-2011 Gunter Winkler, David Bellot
//
//  Distributed under the Boost Software License, Version 1.0. (See
//  accompanying file LICENSE_1_0.txt or copy at
//  http://www.boost.org/LICENSE_1_0.txt)

// ublas headers

#include <boost/numeric/ublas/experimental/sparse_view.hpp>

#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/matrix_sparse.hpp>
#include <boost/numeric/ublas/io.hpp>

#include <boost/numeric/ublas/traits/c_array.hpp>

// other boost headers

// headers for testcase

#define BOOST_TEST_MODULE SparseMatrixErasureTest
#include <boost/test/included/unit_test.hpp>

// standard and system headers

#include <iostream>
#include <string>

namespace ublas = boost::numeric::ublas;

    /*
      sparse input matrix:

      1 2 0 0
      0 3 9 0
      0 1 4 0
    */

    static const std::string inputMatrix = "[3,4]((1,2,0,0),(0,3,9,0),(0,1,4,0))\n";

    const unsigned int NNZ  = 6;
    const unsigned int IB   = 1;
    const double VA[]       = { 1.0, 2.0, 3.0, 9.0, 1.0, 4.0 };
    const unsigned int IA[] = { 1, 3, 5, 7 };
    const unsigned int JA[] = { 1, 2, 2, 3, 2, 3 };

BOOST_AUTO_TEST_CASE( test_construction_and_basic_operations )
{

    typedef ublas::matrix<double> DENSE_MATRIX;
    
    // prepare data

    DENSE_MATRIX A;

    std::istringstream iss(inputMatrix);
    iss >> A;

    std::cout << A << std::endl;

    std::cout << ( ublas::make_compressed_matrix_view<ublas::row_major,IB>(3,4,NNZ,IA,JA,VA) ) << std::endl;

    typedef ublas::compressed_matrix_view<ublas::row_major, IB, unsigned int [4], unsigned int [NNZ], double[NNZ]> COMPMATVIEW;

    COMPMATVIEW viewA(3,4,NNZ,IA,JA,VA);

    std::cout << viewA << std::endl;

}



BOOST_AUTO_TEST_CASE( test_construction_from_pointers )
{

    std::cout << ( ublas::make_compressed_matrix_view<ublas::column_major,IB>(4,3,NNZ
                                                                              , ublas::c_array_view<const unsigned int>(4,&(IA[0]))
                                                                              , ublas::c_array_view<const unsigned int>(6,&(JA[0]))
                                                                              , ublas::c_array_view<const double>(6,&(VA[0]))) ) << std::endl;

    unsigned int * ia = new unsigned int[4]();
    unsigned int * ja = new unsigned int[6]();
    double * va = new double[6]();

    std::copy(&(IA[0]),&(IA[4]),ia);
    std::copy(&(JA[0]),&(JA[6]),ja);
    std::copy(&(VA[0]),&(VA[6]),va);

    typedef ublas::compressed_matrix_view<ublas::column_major
      , IB
      , ublas::c_array_view<unsigned int>
      , ublas::c_array_view<unsigned int>
      , ublas::c_array_view<double> > COMPMATVIEW;

    COMPMATVIEW viewA(4,3,NNZ
                      , ublas::c_array_view<unsigned int>(4,ia)
                      , ublas::c_array_view<unsigned int>(6,ja)
                      , ublas::c_array_view<double>(6,va));

    std::cout << viewA << std::endl;

    delete[] va;
    delete[] ja;
    delete[] ia;

}