1 // Copyright (c) 2011 David Bellot
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)
7 #ifndef BOOST_UBLAS_NO_ELEMENT_PROXIES
8 # define BOOST_UBLAS_NO_ELEMENT_PROXIES
11 #include <boost/numeric/ublas/assignment.hpp>
12 #include <boost/numeric/ublas/vector.hpp>
13 #include <boost/numeric/ublas/vector_sparse.hpp>
14 #include <boost/numeric/ublas/vector_expression.hpp>
15 #include <boost/numeric/ublas/io.hpp>
16 #include "common/testhelper.hpp"
19 const double TOL
= 1e-15;
22 bool check_sortedness(const boost::numeric::ublas::coordinate_vector
<T
>& vector
) {
24 typedef boost::numeric::ublas::coordinate_vector
<T
> vector_type
;
25 typename
vector_type::index_array_type idx
= vector
.index_data();
26 typename
vector_type::size_type size
= vector
.filled();
28 for (typename
vector_type::size_type i
= 0; i
+ 1 < size
&& result
; ++ i
) {
29 result
&= (idx
[i
] < idx
[i
+ 1]);
34 void print_entries(size_t size
,
35 const std::vector
<size_t>& entries
)
37 std::cerr
<< "Error entries - Size:" << size
<< ". Entries: ";
38 for (size_t i
= 0; i
< entries
.size(); ++ i
) {
39 std::cerr
<< entries
[i
] << "; ";
44 BOOST_UBLAS_TEST_DEF( test_coordinate_vector_inplace_merge_random
)
46 const size_t max_repeats
= 100;
47 const size_t max_size
= 100;
48 const size_t dim_var
= 10;
49 const size_t nr_entries
= 10;
51 for (size_t repeats
= 1; repeats
< max_repeats
; ++repeats
) {
52 for (size_t size
= 1; size
< max_size
; size
+= 5) {
53 size_t size_vec
= size
+ rand() % dim_var
;
55 boost::numeric::ublas::coordinate_vector
<double> vector_coord(size_vec
);
56 boost::numeric::ublas::vector
<double> vector_dense(size_vec
, 0);
60 std::vector
<size_t> entries
;
61 for (size_t entry
= 0; entry
< nr_entries
; ++ entry
) {
62 int x
= rand() % size_vec
;
64 vector_coord
.append_element(x
, 1);
70 bool sorted
= check_sortedness(vector_coord
);
71 bool identical
= compare_distance(vector_coord
, vector_dense
, TOL
);
72 if (!(sorted
&& identical
)) {
73 print_entries(size_vec
, entries
);
75 BOOST_UBLAS_TEST_CHECK( check_sortedness(vector_coord
) );
76 BOOST_UBLAS_TEST_CHECK( compare_distance(vector_coord
, vector_dense
, TOL
) );
79 for (size_t entry
= 0; entry
< nr_entries
; ++ entry
) {
80 int x
= rand() % size_vec
;
88 bool sorted
= check_sortedness(vector_coord
);
89 bool identical
= compare_distance(vector_coord
, vector_dense
, TOL
);
90 if (!(sorted
&& identical
)) {
91 print_entries(size_vec
, entries
);
93 BOOST_UBLAS_TEST_CHECK( sorted
);
94 BOOST_UBLAS_TEST_CHECK( identical
);
102 BOOST_UBLAS_TEST_BEGIN();
104 BOOST_UBLAS_TEST_DO( test_coordinate_vector_inplace_merge_random
);
106 BOOST_UBLAS_TEST_END();