| 1 | /* |
|---|
| 2 | * Copyright (c) 2004 Michael Stevens |
|---|
| 3 | * Use, modification and distribution are subject to the |
|---|
| 4 | * Boost Software License, Version 1.0. (See accompanying file |
|---|
| 5 | * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 6 | */ |
|---|
| 7 | |
|---|
| 8 | /* |
|---|
| 9 | * Default construct test when possible |
|---|
| 10 | */ |
|---|
| 11 | |
|---|
| 12 | template <class E> |
|---|
| 13 | struct default_construct |
|---|
| 14 | { |
|---|
| 15 | static void test() {} |
|---|
| 16 | }; |
|---|
| 17 | template <class VC> |
|---|
| 18 | struct default_construct<boost::numeric::ublas::vector_container<VC> > |
|---|
| 19 | { |
|---|
| 20 | static void test () |
|---|
| 21 | { |
|---|
| 22 | VC default_constuct; |
|---|
| 23 | initialize_vector (default_constuct); |
|---|
| 24 | std::cout << "default construct = " << default_constuct << std::endl; |
|---|
| 25 | } |
|---|
| 26 | }; |
|---|
| 27 | template <class MC> |
|---|
| 28 | struct default_construct<boost::numeric::ublas::matrix_container<MC> > |
|---|
| 29 | { |
|---|
| 30 | static void test () |
|---|
| 31 | { |
|---|
| 32 | MC default_constuct; |
|---|
| 33 | initialize_vector (default_constuct); |
|---|
| 34 | std::cout << "default construct = " << default_constuct << std::endl; |
|---|
| 35 | } |
|---|
| 36 | }; |
|---|
| 37 | |
|---|
| 38 | /* |
|---|
| 39 | * Initialise test values in vector/matrix |
|---|
| 40 | */ |
|---|
| 41 | |
|---|
| 42 | template<class V> |
|---|
| 43 | void initialize_vector (V &v) { |
|---|
| 44 | typename V::size_type size = v.size (); |
|---|
| 45 | for (typename V::size_type i = 0; i < size; ++ i) |
|---|
| 46 | v [i] = typename V::value_type (i + 1); |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | template<class M> |
|---|
| 50 | void initialize_matrix_impl (M &m, ublas::packed_proxy_tag) { |
|---|
| 51 | typename M::size_type size1 = m.size1 (); |
|---|
| 52 | #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION |
|---|
| 53 | for (typename M::iterator1 i = m.begin1(); i != m.end1(); ++ i) |
|---|
| 54 | for (typename M::iterator2 j = i.begin(); j != i.end(); ++ j) |
|---|
| 55 | *j = typename M::value_type (i.index1() * size1 + j.index2() + 1); |
|---|
| 56 | #else |
|---|
| 57 | for (typename M::iterator1 i = m.begin1(); i != m.end1(); ++ i) |
|---|
| 58 | for (typename M::iterator2 j = ublas::begin (i, ublas::iterator1_tag ()); j != ublas::end (i, ublas::iterator1_tag ()); ++ j) |
|---|
| 59 | *j = typename M::value_type (i.index1() * size1 + j.index2() + 1); |
|---|
| 60 | #endif |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | template<class M> |
|---|
| 64 | void initialize_matrix_impl (M &m, ublas::sparse_proxy_tag) { |
|---|
| 65 | typename M::size_type size1 = m.size1 (); |
|---|
| 66 | typename M::size_type size2 = m.size2 (); |
|---|
| 67 | for (typename M::size_type i = 0; i < size1; ++ i) |
|---|
| 68 | for (typename M::size_type j = 0; j < size2; ++ j) |
|---|
| 69 | m (i, j) = typename M::value_type (i * size1 + j + 1.f); |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | template<class M> |
|---|
| 73 | void initialize_matrix (M &m) { |
|---|
| 74 | initialize_matrix_impl (m, typename M::storage_category()); |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | template<class M> |
|---|
| 78 | void initialize_matrix (M &m, ublas::lower_tag) { |
|---|
| 79 | typename M::size_type size1 = m.size1 (); |
|---|
| 80 | typename M::size_type size2 = m.size2 (); |
|---|
| 81 | for (typename M::size_type i = 0; i < size1; ++ i) { |
|---|
| 82 | typename M::size_type j = 0; |
|---|
| 83 | for (; j <= i; ++ j) |
|---|
| 84 | m (i, j) = i * size1 + j + 1.f; |
|---|
| 85 | for (; j < size2; ++ j) |
|---|
| 86 | m (i, j) = 0.f; |
|---|
| 87 | } |
|---|
| 88 | } |
|---|
| 89 | template<class M> |
|---|
| 90 | void initialize_matrix (M &m, ublas::upper_tag) { |
|---|
| 91 | typename M::size_type size1 = m.size1 (); |
|---|
| 92 | typename M::size_type size2 = m.size2 (); |
|---|
| 93 | for (typename M::size_type i = 0; i < size1; ++ i) { |
|---|
| 94 | typename M::size_type j = 0; |
|---|
| 95 | for (; j < i; ++ j) |
|---|
| 96 | m (i, j) = 0.f; |
|---|
| 97 | for (; j < size2; ++ j) |
|---|
| 98 | m (i, j) = i * size1 + j + 1.f; |
|---|
| 99 | } |
|---|
| 100 | } |
|---|