1 | #include <boost/numeric/ublas/io.hpp>
|
---|
2 | #include <boost/numeric/ublas/matrix.hpp>
|
---|
3 | #include <boost/numeric/ublas/triangular.hpp>
|
---|
4 | #include <boost/numeric/ublas/vector.hpp>
|
---|
5 | #include <cstddef>
|
---|
6 | #include <iostream>
|
---|
7 |
|
---|
8 | namespace ublas = boost::numeric::ublas;
|
---|
9 |
|
---|
10 | typedef int value_type;
|
---|
11 |
|
---|
12 | void test_integral_vector()
|
---|
13 | {
|
---|
14 | std::cout << "[test_integral_vector] BEGIN" << std::endl;
|
---|
15 |
|
---|
16 | std::size_t n(5);
|
---|
17 |
|
---|
18 | ublas::zero_vector<value_type> in(n);
|
---|
19 |
|
---|
20 | std::cerr << "[test_integral_vector] Input Vector: " << in << std::endl;
|
---|
21 |
|
---|
22 | // Test copy-construction
|
---|
23 | try
|
---|
24 | {
|
---|
25 | ublas::vector<value_type> out(in);
|
---|
26 |
|
---|
27 | std::cout << "[test_integral_vector] Copy-construction succeeded." << std::endl;
|
---|
28 | std::cout << "[test_integral_vector] Copy-constructed Output Vector: " << out << std::endl;
|
---|
29 | }
|
---|
30 | catch (...)
|
---|
31 | {
|
---|
32 | std::cout << "[test_integral_vector] Copy-construction failed." << std::endl;
|
---|
33 | }
|
---|
34 |
|
---|
35 | // Test copy-assignement
|
---|
36 | try
|
---|
37 | {
|
---|
38 | ublas::vector<value_type> out;
|
---|
39 | out = in;
|
---|
40 |
|
---|
41 | std::cout << "[test_integral_vector] Copy-construction succeeded." << std::endl;
|
---|
42 | std::cout << "[test_integral_vector] Copy-constructed Output Vector: " << out << std::endl;
|
---|
43 | }
|
---|
44 | catch (...)
|
---|
45 | {
|
---|
46 | std::cout << "[test_integral_vector] Copy-assignement failed." << std::endl;
|
---|
47 | }
|
---|
48 |
|
---|
49 | std::cout << "[test_integral_vector] END" << std::endl;
|
---|
50 | }
|
---|
51 |
|
---|
52 |
|
---|
53 | void test_integral_matrix()
|
---|
54 | {
|
---|
55 | std::cout << "[test_integral_matrix] BEGIN" << std::endl;
|
---|
56 |
|
---|
57 | std::size_t n(5);
|
---|
58 |
|
---|
59 | ublas::triangular_matrix<value_type,ublas::lower> IN(n,n);
|
---|
60 |
|
---|
61 | // Initialize the input matrix
|
---|
62 | for (std::size_t i = 0; i < n; ++i)
|
---|
63 | {
|
---|
64 | for (std::size_t j = 0; j <= i; ++j)
|
---|
65 | {
|
---|
66 | IN(i,j) = 2*i+j;
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | std::cout << "[test_integral_matrix] Input Matrix: " << IN << std::endl;
|
---|
71 |
|
---|
72 | // Test copy-construction
|
---|
73 | try
|
---|
74 | {
|
---|
75 | ublas::matrix<value_type> OUT(IN);
|
---|
76 |
|
---|
77 | std::cout << "[test_integral_matrix] Copy-construction succeeded." << std::endl;
|
---|
78 | std::cout << "[test_integral_matrix] Copy-constructed Output Matrix: " << OUT << std::endl;
|
---|
79 | }
|
---|
80 | catch (...)
|
---|
81 | {
|
---|
82 | std::cout << "[test_integral_matrix] Copy-construction failed." << std::endl;
|
---|
83 | }
|
---|
84 |
|
---|
85 | // Test copy-assignement
|
---|
86 | try
|
---|
87 | {
|
---|
88 | ublas::matrix<value_type> OUT(n,n);
|
---|
89 | OUT = IN;
|
---|
90 |
|
---|
91 | std::cout << "[test_integral_matrix] Copy-assignement succeeded." << std::endl;
|
---|
92 | std::cout << "[test_integral_matrix] Copy-assigned Output Matrix: " << OUT << std::endl;
|
---|
93 | }
|
---|
94 | catch (...)
|
---|
95 | {
|
---|
96 | std::cout << "[test_integral_matrix] Copy-assignement failed." << std::endl;
|
---|
97 | }
|
---|
98 |
|
---|
99 | std::cout << "[test_integral_matrix] END" << std::endl;
|
---|
100 |
|
---|
101 | }
|
---|
102 |
|
---|
103 |
|
---|
104 | int main()
|
---|
105 | {
|
---|
106 | test_integral_vector();
|
---|
107 | test_integral_matrix();
|
---|
108 | }
|
---|
109 |
|
---|