]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/numeric/ublas/test/sparse_view_test.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / numeric / ublas / test / sparse_view_test.cpp
1 // Copyright (c) 2009-2011 Gunter Winkler, David Bellot
2 //
3 // Distributed under the Boost Software License, Version 1.0. (See
4 // accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6
7 // ublas headers
8
9 #include <boost/numeric/ublas/experimental/sparse_view.hpp>
10
11 #include <boost/numeric/ublas/matrix.hpp>
12 #include <boost/numeric/ublas/matrix_sparse.hpp>
13 #include <boost/numeric/ublas/io.hpp>
14
15 #include <boost/numeric/ublas/traits/c_array.hpp>
16
17 // other boost headers
18
19 // headers for testcase
20
21 #define BOOST_TEST_MODULE SparseMatrixErasureTest
22 #include <boost/test/included/unit_test.hpp>
23
24 // standard and system headers
25
26 #include <iostream>
27 #include <string>
28
29 namespace ublas = boost::numeric::ublas;
30
31 /*
32 sparse input matrix:
33
34 1 2 0 0
35 0 3 9 0
36 0 1 4 0
37 */
38
39 static const std::string inputMatrix = "[3,4]((1,2,0,0),(0,3,9,0),(0,1,4,0))\n";
40
41 const unsigned int NNZ = 6;
42 const unsigned int IB = 1;
43 const double VA[] = { 1.0, 2.0, 3.0, 9.0, 1.0, 4.0 };
44 const unsigned int IA[] = { 1, 3, 5, 7 };
45 const unsigned int JA[] = { 1, 2, 2, 3, 2, 3 };
46
47 BOOST_AUTO_TEST_CASE( test_construction_and_basic_operations )
48 {
49
50 typedef ublas::matrix<double> DENSE_MATRIX;
51
52 // prepare data
53
54 DENSE_MATRIX A;
55
56 std::istringstream iss(inputMatrix);
57 iss >> A;
58
59 std::cout << A << std::endl;
60
61 std::cout << ( ublas::make_compressed_matrix_view<ublas::row_major,IB>(3,4,NNZ,IA,JA,VA) ) << std::endl;
62
63 typedef ublas::compressed_matrix_view<ublas::row_major, IB, unsigned int [4], unsigned int [NNZ], double[NNZ]> COMPMATVIEW;
64
65 COMPMATVIEW viewA(3,4,NNZ,IA,JA,VA);
66
67 std::cout << viewA << std::endl;
68
69 }
70
71
72
73 BOOST_AUTO_TEST_CASE( test_construction_from_pointers )
74 {
75
76 std::cout << ( ublas::make_compressed_matrix_view<ublas::column_major,IB>(4,3,NNZ
77 , ublas::c_array_view<const unsigned int>(4,&(IA[0]))
78 , ublas::c_array_view<const unsigned int>(6,&(JA[0]))
79 , ublas::c_array_view<const double>(6,&(VA[0]))) ) << std::endl;
80
81 unsigned int * ia = new unsigned int[4]();
82 unsigned int * ja = new unsigned int[6]();
83 double * va = new double[6]();
84
85 std::copy(&(IA[0]),&(IA[4]),ia);
86 std::copy(&(JA[0]),&(JA[6]),ja);
87 std::copy(&(VA[0]),&(VA[6]),va);
88
89 typedef ublas::compressed_matrix_view<ublas::column_major
90 , IB
91 , ublas::c_array_view<unsigned int>
92 , ublas::c_array_view<unsigned int>
93 , ublas::c_array_view<double> > COMPMATVIEW;
94
95 COMPMATVIEW viewA(4,3,NNZ
96 , ublas::c_array_view<unsigned int>(4,ia)
97 , ublas::c_array_view<unsigned int>(6,ja)
98 , ublas::c_array_view<double>(6,va));
99
100 std::cout << viewA << std::endl;
101
102 delete[] va;
103 delete[] ja;
104 delete[] ia;
105
106 }