annotate DEPENDENCIES/generic/include/boost/numeric/ublas/operation_blocked.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 //
Chris@16 2 // Copyright (c) 2000-2002
Chris@16 3 // Joerg Walter, Mathias Koch
Chris@16 4 //
Chris@16 5 // Distributed under the Boost Software License, Version 1.0. (See
Chris@16 6 // accompanying file LICENSE_1_0.txt or copy at
Chris@16 7 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 8 //
Chris@16 9 // The authors gratefully acknowledge the support of
Chris@16 10 // GeNeSys mbH & Co. KG in producing this work.
Chris@16 11 //
Chris@16 12
Chris@16 13 #ifndef _BOOST_UBLAS_OPERATION_BLOCKED_
Chris@16 14 #define _BOOST_UBLAS_OPERATION_BLOCKED_
Chris@16 15
Chris@16 16 #include <boost/numeric/ublas/traits.hpp>
Chris@16 17 #include <boost/numeric/ublas/detail/vector_assign.hpp> // indexing_vector_assign
Chris@16 18 #include <boost/numeric/ublas/detail/matrix_assign.hpp> // indexing_matrix_assign
Chris@16 19
Chris@16 20
Chris@16 21 namespace boost { namespace numeric { namespace ublas {
Chris@16 22
Chris@16 23 template<class V, typename V::size_type BS, class E1, class E2>
Chris@16 24 BOOST_UBLAS_INLINE
Chris@16 25 V
Chris@16 26 block_prod (const matrix_expression<E1> &e1,
Chris@16 27 const vector_expression<E2> &e2) {
Chris@16 28 typedef V vector_type;
Chris@16 29 typedef const E1 expression1_type;
Chris@16 30 typedef const E2 expression2_type;
Chris@16 31 typedef typename V::size_type size_type;
Chris@16 32 typedef typename V::value_type value_type;
Chris@16 33 const size_type block_size = BS;
Chris@16 34
Chris@16 35 V v (e1 ().size1 ());
Chris@16 36 #if BOOST_UBLAS_TYPE_CHECK
Chris@16 37 vector<value_type> cv (v.size ());
Chris@16 38 typedef typename type_traits<value_type>::real_type real_type;
Chris@16 39 real_type verrorbound (norm_1 (v) + norm_1 (e1) * norm_1 (e2));
Chris@16 40 indexing_vector_assign<scalar_assign> (cv, prod (e1, e2));
Chris@16 41 #endif
Chris@16 42 size_type i_size = e1 ().size1 ();
Chris@16 43 size_type j_size = BOOST_UBLAS_SAME (e1 ().size2 (), e2 ().size ());
Chris@16 44 for (size_type i_begin = 0; i_begin < i_size; i_begin += block_size) {
Chris@16 45 size_type i_end = i_begin + (std::min) (i_size - i_begin, block_size);
Chris@16 46 // FIX: never ignore Martin Weiser's advice ;-(
Chris@16 47 #ifdef BOOST_UBLAS_NO_CACHE
Chris@16 48 vector_range<vector_type> v_range (v, range (i_begin, i_end));
Chris@16 49 #else
Chris@16 50 // vector<value_type, bounded_array<value_type, block_size> > v_range (i_end - i_begin);
Chris@16 51 vector<value_type> v_range (i_end - i_begin);
Chris@16 52 #endif
Chris@16 53 v_range.assign (zero_vector<value_type> (i_end - i_begin));
Chris@16 54 for (size_type j_begin = 0; j_begin < j_size; j_begin += block_size) {
Chris@16 55 size_type j_end = j_begin + (std::min) (j_size - j_begin, block_size);
Chris@16 56 #ifdef BOOST_UBLAS_NO_CACHE
Chris@16 57 const matrix_range<expression1_type> e1_range (e1 (), range (i_begin, i_end), range (j_begin, j_end));
Chris@16 58 const vector_range<expression2_type> e2_range (e2 (), range (j_begin, j_end));
Chris@16 59 v_range.plus_assign (prod (e1_range, e2_range));
Chris@16 60 #else
Chris@16 61 // const matrix<value_type, row_major, bounded_array<value_type, block_size * block_size> > e1_range (project (e1 (), range (i_begin, i_end), range (j_begin, j_end)));
Chris@16 62 // const vector<value_type, bounded_array<value_type, block_size> > e2_range (project (e2 (), range (j_begin, j_end)));
Chris@16 63 const matrix<value_type, row_major> e1_range (project (e1 (), range (i_begin, i_end), range (j_begin, j_end)));
Chris@16 64 const vector<value_type> e2_range (project (e2 (), range (j_begin, j_end)));
Chris@16 65 v_range.plus_assign (prod (e1_range, e2_range));
Chris@16 66 #endif
Chris@16 67 }
Chris@16 68 #ifndef BOOST_UBLAS_NO_CACHE
Chris@16 69 project (v, range (i_begin, i_end)).assign (v_range);
Chris@16 70 #endif
Chris@16 71 }
Chris@16 72 #if BOOST_UBLAS_TYPE_CHECK
Chris@16 73 BOOST_UBLAS_CHECK (norm_1 (v - cv) <= 2 * std::numeric_limits<real_type>::epsilon () * verrorbound, internal_logic ());
Chris@16 74 #endif
Chris@16 75 return v;
Chris@16 76 }
Chris@16 77
Chris@16 78 template<class V, typename V::size_type BS, class E1, class E2>
Chris@16 79 BOOST_UBLAS_INLINE
Chris@16 80 V
Chris@16 81 block_prod (const vector_expression<E1> &e1,
Chris@16 82 const matrix_expression<E2> &e2) {
Chris@16 83 typedef V vector_type;
Chris@16 84 typedef const E1 expression1_type;
Chris@16 85 typedef const E2 expression2_type;
Chris@16 86 typedef typename V::size_type size_type;
Chris@16 87 typedef typename V::value_type value_type;
Chris@16 88 const size_type block_size = BS;
Chris@16 89
Chris@16 90 V v (e2 ().size2 ());
Chris@16 91 #if BOOST_UBLAS_TYPE_CHECK
Chris@16 92 vector<value_type> cv (v.size ());
Chris@16 93 typedef typename type_traits<value_type>::real_type real_type;
Chris@16 94 real_type verrorbound (norm_1 (v) + norm_1 (e1) * norm_1 (e2));
Chris@16 95 indexing_vector_assign<scalar_assign> (cv, prod (e1, e2));
Chris@16 96 #endif
Chris@16 97 size_type i_size = BOOST_UBLAS_SAME (e1 ().size (), e2 ().size1 ());
Chris@16 98 size_type j_size = e2 ().size2 ();
Chris@16 99 for (size_type j_begin = 0; j_begin < j_size; j_begin += block_size) {
Chris@16 100 size_type j_end = j_begin + (std::min) (j_size - j_begin, block_size);
Chris@16 101 // FIX: never ignore Martin Weiser's advice ;-(
Chris@16 102 #ifdef BOOST_UBLAS_NO_CACHE
Chris@16 103 vector_range<vector_type> v_range (v, range (j_begin, j_end));
Chris@16 104 #else
Chris@16 105 // vector<value_type, bounded_array<value_type, block_size> > v_range (j_end - j_begin);
Chris@16 106 vector<value_type> v_range (j_end - j_begin);
Chris@16 107 #endif
Chris@16 108 v_range.assign (zero_vector<value_type> (j_end - j_begin));
Chris@16 109 for (size_type i_begin = 0; i_begin < i_size; i_begin += block_size) {
Chris@16 110 size_type i_end = i_begin + (std::min) (i_size - i_begin, block_size);
Chris@16 111 #ifdef BOOST_UBLAS_NO_CACHE
Chris@16 112 const vector_range<expression1_type> e1_range (e1 (), range (i_begin, i_end));
Chris@16 113 const matrix_range<expression2_type> e2_range (e2 (), range (i_begin, i_end), range (j_begin, j_end));
Chris@16 114 #else
Chris@16 115 // const vector<value_type, bounded_array<value_type, block_size> > e1_range (project (e1 (), range (i_begin, i_end)));
Chris@16 116 // const matrix<value_type, column_major, bounded_array<value_type, block_size * block_size> > e2_range (project (e2 (), range (i_begin, i_end), range (j_begin, j_end)));
Chris@16 117 const vector<value_type> e1_range (project (e1 (), range (i_begin, i_end)));
Chris@16 118 const matrix<value_type, column_major> e2_range (project (e2 (), range (i_begin, i_end), range (j_begin, j_end)));
Chris@16 119 #endif
Chris@16 120 v_range.plus_assign (prod (e1_range, e2_range));
Chris@16 121 }
Chris@16 122 #ifndef BOOST_UBLAS_NO_CACHE
Chris@16 123 project (v, range (j_begin, j_end)).assign (v_range);
Chris@16 124 #endif
Chris@16 125 }
Chris@16 126 #if BOOST_UBLAS_TYPE_CHECK
Chris@16 127 BOOST_UBLAS_CHECK (norm_1 (v - cv) <= 2 * std::numeric_limits<real_type>::epsilon () * verrorbound, internal_logic ());
Chris@16 128 #endif
Chris@16 129 return v;
Chris@16 130 }
Chris@16 131
Chris@16 132 template<class M, typename M::size_type BS, class E1, class E2>
Chris@16 133 BOOST_UBLAS_INLINE
Chris@16 134 M
Chris@16 135 block_prod (const matrix_expression<E1> &e1,
Chris@16 136 const matrix_expression<E2> &e2,
Chris@16 137 row_major_tag) {
Chris@16 138 typedef M matrix_type;
Chris@16 139 typedef const E1 expression1_type;
Chris@16 140 typedef const E2 expression2_type;
Chris@16 141 typedef typename M::size_type size_type;
Chris@16 142 typedef typename M::value_type value_type;
Chris@16 143 const size_type block_size = BS;
Chris@16 144
Chris@16 145 M m (e1 ().size1 (), e2 ().size2 ());
Chris@16 146 #if BOOST_UBLAS_TYPE_CHECK
Chris@16 147 matrix<value_type, row_major> cm (m.size1 (), m.size2 ());
Chris@16 148 typedef typename type_traits<value_type>::real_type real_type;
Chris@16 149 real_type merrorbound (norm_1 (m) + norm_1 (e1) * norm_1 (e2));
Chris@16 150 indexing_matrix_assign<scalar_assign> (cm, prod (e1, e2), row_major_tag ());
Chris@16 151 disable_type_check<bool>::value = true;
Chris@16 152 #endif
Chris@16 153 size_type i_size = e1 ().size1 ();
Chris@16 154 size_type j_size = e2 ().size2 ();
Chris@16 155 size_type k_size = BOOST_UBLAS_SAME (e1 ().size2 (), e2 ().size1 ());
Chris@16 156 for (size_type i_begin = 0; i_begin < i_size; i_begin += block_size) {
Chris@16 157 size_type i_end = i_begin + (std::min) (i_size - i_begin, block_size);
Chris@16 158 for (size_type j_begin = 0; j_begin < j_size; j_begin += block_size) {
Chris@16 159 size_type j_end = j_begin + (std::min) (j_size - j_begin, block_size);
Chris@16 160 // FIX: never ignore Martin Weiser's advice ;-(
Chris@16 161 #ifdef BOOST_UBLAS_NO_CACHE
Chris@16 162 matrix_range<matrix_type> m_range (m, range (i_begin, i_end), range (j_begin, j_end));
Chris@16 163 #else
Chris@16 164 // matrix<value_type, row_major, bounded_array<value_type, block_size * block_size> > m_range (i_end - i_begin, j_end - j_begin);
Chris@16 165 matrix<value_type, row_major> m_range (i_end - i_begin, j_end - j_begin);
Chris@16 166 #endif
Chris@16 167 m_range.assign (zero_matrix<value_type> (i_end - i_begin, j_end - j_begin));
Chris@16 168 for (size_type k_begin = 0; k_begin < k_size; k_begin += block_size) {
Chris@16 169 size_type k_end = k_begin + (std::min) (k_size - k_begin, block_size);
Chris@16 170 #ifdef BOOST_UBLAS_NO_CACHE
Chris@16 171 const matrix_range<expression1_type> e1_range (e1 (), range (i_begin, i_end), range (k_begin, k_end));
Chris@16 172 const matrix_range<expression2_type> e2_range (e2 (), range (k_begin, k_end), range (j_begin, j_end));
Chris@16 173 #else
Chris@16 174 // const matrix<value_type, row_major, bounded_array<value_type, block_size * block_size> > e1_range (project (e1 (), range (i_begin, i_end), range (k_begin, k_end)));
Chris@16 175 // const matrix<value_type, column_major, bounded_array<value_type, block_size * block_size> > e2_range (project (e2 (), range (k_begin, k_end), range (j_begin, j_end)));
Chris@16 176 const matrix<value_type, row_major> e1_range (project (e1 (), range (i_begin, i_end), range (k_begin, k_end)));
Chris@16 177 const matrix<value_type, column_major> e2_range (project (e2 (), range (k_begin, k_end), range (j_begin, j_end)));
Chris@16 178 #endif
Chris@16 179 m_range.plus_assign (prod (e1_range, e2_range));
Chris@16 180 }
Chris@16 181 #ifndef BOOST_UBLAS_NO_CACHE
Chris@16 182 project (m, range (i_begin, i_end), range (j_begin, j_end)).assign (m_range);
Chris@16 183 #endif
Chris@16 184 }
Chris@16 185 }
Chris@16 186 #if BOOST_UBLAS_TYPE_CHECK
Chris@16 187 disable_type_check<bool>::value = false;
Chris@16 188 BOOST_UBLAS_CHECK (norm_1 (m - cm) <= 2 * std::numeric_limits<real_type>::epsilon () * merrorbound, internal_logic ());
Chris@16 189 #endif
Chris@16 190 return m;
Chris@16 191 }
Chris@16 192
Chris@16 193 template<class M, typename M::size_type BS, class E1, class E2>
Chris@16 194 BOOST_UBLAS_INLINE
Chris@16 195 M
Chris@16 196 block_prod (const matrix_expression<E1> &e1,
Chris@16 197 const matrix_expression<E2> &e2,
Chris@16 198 column_major_tag) {
Chris@16 199 typedef M matrix_type;
Chris@16 200 typedef const E1 expression1_type;
Chris@16 201 typedef const E2 expression2_type;
Chris@16 202 typedef typename M::size_type size_type;
Chris@16 203 typedef typename M::value_type value_type;
Chris@16 204 const size_type block_size = BS;
Chris@16 205
Chris@16 206 M m (e1 ().size1 (), e2 ().size2 ());
Chris@16 207 #if BOOST_UBLAS_TYPE_CHECK
Chris@16 208 matrix<value_type, column_major> cm (m.size1 (), m.size2 ());
Chris@16 209 typedef typename type_traits<value_type>::real_type real_type;
Chris@16 210 real_type merrorbound (norm_1 (m) + norm_1 (e1) * norm_1 (e2));
Chris@16 211 indexing_matrix_assign<scalar_assign> (cm, prod (e1, e2), column_major_tag ());
Chris@16 212 disable_type_check<bool>::value = true;
Chris@16 213 #endif
Chris@16 214 size_type i_size = e1 ().size1 ();
Chris@16 215 size_type j_size = e2 ().size2 ();
Chris@16 216 size_type k_size = BOOST_UBLAS_SAME (e1 ().size2 (), e2 ().size1 ());
Chris@16 217 for (size_type j_begin = 0; j_begin < j_size; j_begin += block_size) {
Chris@16 218 size_type j_end = j_begin + (std::min) (j_size - j_begin, block_size);
Chris@16 219 for (size_type i_begin = 0; i_begin < i_size; i_begin += block_size) {
Chris@16 220 size_type i_end = i_begin + (std::min) (i_size - i_begin, block_size);
Chris@16 221 // FIX: never ignore Martin Weiser's advice ;-(
Chris@16 222 #ifdef BOOST_UBLAS_NO_CACHE
Chris@16 223 matrix_range<matrix_type> m_range (m, range (i_begin, i_end), range (j_begin, j_end));
Chris@16 224 #else
Chris@16 225 // matrix<value_type, column_major, bounded_array<value_type, block_size * block_size> > m_range (i_end - i_begin, j_end - j_begin);
Chris@16 226 matrix<value_type, column_major> m_range (i_end - i_begin, j_end - j_begin);
Chris@16 227 #endif
Chris@16 228 m_range.assign (zero_matrix<value_type> (i_end - i_begin, j_end - j_begin));
Chris@16 229 for (size_type k_begin = 0; k_begin < k_size; k_begin += block_size) {
Chris@16 230 size_type k_end = k_begin + (std::min) (k_size - k_begin, block_size);
Chris@16 231 #ifdef BOOST_UBLAS_NO_CACHE
Chris@16 232 const matrix_range<expression1_type> e1_range (e1 (), range (i_begin, i_end), range (k_begin, k_end));
Chris@16 233 const matrix_range<expression2_type> e2_range (e2 (), range (k_begin, k_end), range (j_begin, j_end));
Chris@16 234 #else
Chris@16 235 // const matrix<value_type, row_major, bounded_array<value_type, block_size * block_size> > e1_range (project (e1 (), range (i_begin, i_end), range (k_begin, k_end)));
Chris@16 236 // const matrix<value_type, column_major, bounded_array<value_type, block_size * block_size> > e2_range (project (e2 (), range (k_begin, k_end), range (j_begin, j_end)));
Chris@16 237 const matrix<value_type, row_major> e1_range (project (e1 (), range (i_begin, i_end), range (k_begin, k_end)));
Chris@16 238 const matrix<value_type, column_major> e2_range (project (e2 (), range (k_begin, k_end), range (j_begin, j_end)));
Chris@16 239 #endif
Chris@16 240 m_range.plus_assign (prod (e1_range, e2_range));
Chris@16 241 }
Chris@16 242 #ifndef BOOST_UBLAS_NO_CACHE
Chris@16 243 project (m, range (i_begin, i_end), range (j_begin, j_end)).assign (m_range);
Chris@16 244 #endif
Chris@16 245 }
Chris@16 246 }
Chris@16 247 #if BOOST_UBLAS_TYPE_CHECK
Chris@16 248 disable_type_check<bool>::value = false;
Chris@16 249 BOOST_UBLAS_CHECK (norm_1 (m - cm) <= 2 * std::numeric_limits<real_type>::epsilon () * merrorbound, internal_logic ());
Chris@16 250 #endif
Chris@16 251 return m;
Chris@16 252 }
Chris@16 253
Chris@16 254 // Dispatcher
Chris@16 255 template<class M, typename M::size_type BS, class E1, class E2>
Chris@16 256 BOOST_UBLAS_INLINE
Chris@16 257 M
Chris@16 258 block_prod (const matrix_expression<E1> &e1,
Chris@16 259 const matrix_expression<E2> &e2) {
Chris@16 260 typedef typename M::orientation_category orientation_category;
Chris@16 261 return block_prod<M, BS> (e1, e2, orientation_category ());
Chris@16 262 }
Chris@16 263
Chris@16 264 }}}
Chris@16 265
Chris@16 266 #endif