annotate DEPENDENCIES/generic/include/boost/numeric/odeint/external/thrust/thrust_algebra.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 /*
Chris@16 2 [auto_generated]
Chris@16 3 boost/numeric/odeint/external/thrust/thrust_algebra.hpp
Chris@16 4
Chris@16 5 [begin_description]
Chris@16 6 An algebra for thrusts device_vectors.
Chris@16 7 [end_description]
Chris@16 8
Chris@101 9 Copyright 2010-2013 Mario Mulansky
Chris@101 10 Copyright 2010-2011 Karsten Ahnert
Chris@101 11 Copyright 2013 Kyle Lutz
Chris@16 12
Chris@16 13 Distributed under the Boost Software License, Version 1.0.
Chris@16 14 (See accompanying file LICENSE_1_0.txt or
Chris@16 15 copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 16 */
Chris@16 17
Chris@16 18
Chris@16 19 #ifndef BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_ALGEBRA_HPP_INCLUDED
Chris@16 20 #define BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_ALGEBRA_HPP_INCLUDED
Chris@16 21
Chris@16 22
Chris@16 23 #include <thrust/device_vector.h>
Chris@16 24 #include <thrust/for_each.h>
Chris@16 25 #include <thrust/iterator/zip_iterator.h>
Chris@16 26
Chris@16 27 #include <boost/range.hpp>
Chris@16 28
Chris@16 29 namespace boost {
Chris@16 30 namespace numeric {
Chris@16 31 namespace odeint {
Chris@16 32
Chris@101 33 namespace detail {
Chris@101 34
Chris@101 35 // to use in thrust::reduce
Chris@101 36 template< class Value >
Chris@101 37 struct maximum
Chris@101 38 {
Chris@101 39 template< class Fac1 , class Fac2 >
Chris@101 40 __host__ __device__
Chris@101 41 Value operator()( const Fac1 t1 , const Fac2 t2 ) const
Chris@101 42 {
Chris@101 43 return ( abs( t1 ) < abs( t2 ) ) ? t2 : t1 ;
Chris@101 44 }
Chris@101 45
Chris@101 46 typedef Value result_type;
Chris@101 47 };
Chris@101 48
Chris@101 49 }
Chris@101 50
Chris@101 51
Chris@16 52
Chris@16 53
Chris@16 54 /** ToDO extend until for_each14 for rk78 */
Chris@16 55
Chris@16 56 /*
Chris@16 57 * The const versions are needed for boost.range to work, i.e.
Chris@16 58 * it allows you to do
Chris@16 59 * for_each1( make_pair( vec1.begin() , vec1.begin() + 10 ) , op );
Chris@16 60 */
Chris@16 61
Chris@16 62 struct thrust_algebra
Chris@16 63 {
Chris@16 64 template< class StateType , class Operation >
Chris@16 65 static void for_each1( StateType &s , Operation op )
Chris@16 66 {
Chris@101 67 thrust::for_each( boost::begin(s) , boost::end(s) , op );
Chris@16 68 }
Chris@16 69
Chris@16 70 template< class StateType1 , class StateType2 , class Operation >
Chris@16 71 static void for_each2( StateType1 &s1 , StateType2 &s2 , Operation op )
Chris@16 72 {
Chris@16 73 thrust::for_each(
Chris@16 74 thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
Chris@16 75 boost::begin(s2) ) ) ,
Chris@16 76 thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
Chris@16 77 boost::end(s2) ) ) ,
Chris@16 78 op);
Chris@16 79 }
Chris@16 80
Chris@16 81 template< class StateType1 , class StateType2 , class StateType3 , class Operation >
Chris@16 82 static void for_each3( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , Operation op )
Chris@16 83 {
Chris@16 84 thrust::for_each(
Chris@16 85 thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
Chris@16 86 boost::begin(s2) ,
Chris@16 87 boost::begin(s3) ) ) ,
Chris@16 88 thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
Chris@16 89 boost::end(s2) ,
Chris@16 90 boost::end(s3) ) ) ,
Chris@16 91 op);
Chris@16 92 }
Chris@16 93
Chris@16 94 template< class StateType1 , class StateType2 , class StateType3 , class StateType4 ,
Chris@16 95 class Operation >
Chris@16 96 static void for_each4( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 ,
Chris@16 97 Operation op )
Chris@16 98 {
Chris@16 99 thrust::for_each(
Chris@16 100 thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
Chris@16 101 boost::begin(s2) ,
Chris@16 102 boost::begin(s3) ,
Chris@16 103 boost::begin(s4) ) ) ,
Chris@16 104 thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
Chris@16 105 boost::end(s2) ,
Chris@16 106 boost::end(s3) ,
Chris@16 107 boost::end(s4) ) ) ,
Chris@16 108 op);
Chris@16 109 }
Chris@16 110
Chris@16 111 template< class StateType1 , class StateType2 , class StateType3 ,
Chris@16 112 class StateType4 , class StateType5 ,class Operation >
Chris@16 113 static void for_each5( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 ,
Chris@16 114 StateType5 &s5 , Operation op )
Chris@16 115 {
Chris@16 116 thrust::for_each(
Chris@16 117 thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
Chris@16 118 boost::begin(s2) ,
Chris@16 119 boost::begin(s3) ,
Chris@16 120 boost::begin(s4) ,
Chris@16 121 boost::begin(s5) ) ) ,
Chris@16 122 thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
Chris@16 123 boost::end(s2) ,
Chris@16 124 boost::end(s3) ,
Chris@16 125 boost::end(s4) ,
Chris@16 126 boost::end(s5) ) ) ,
Chris@16 127 op);
Chris@16 128 }
Chris@16 129
Chris@16 130 template< class StateType1 , class StateType2 , class StateType3 ,
Chris@16 131 class StateType4 , class StateType5 , class StateType6 , class Operation >
Chris@16 132 static void for_each6( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 ,
Chris@16 133 StateType5 &s5 , StateType6 &s6 , Operation op )
Chris@16 134 {
Chris@16 135 thrust::for_each(
Chris@16 136 thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
Chris@16 137 boost::begin(s2) ,
Chris@16 138 boost::begin(s3) ,
Chris@16 139 boost::begin(s4) ,
Chris@16 140 boost::begin(s5) ,
Chris@16 141 boost::begin(s6) ) ) ,
Chris@16 142 thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
Chris@16 143 boost::end(s2) ,
Chris@16 144 boost::end(s3) ,
Chris@16 145 boost::end(s4) ,
Chris@16 146 boost::end(s5) ,
Chris@16 147 boost::end(s6) ) ) ,
Chris@16 148 op);
Chris@16 149 }
Chris@16 150
Chris@16 151 template< class StateType1 , class StateType2 , class StateType3 , class StateType4 ,
Chris@16 152 class StateType5 , class StateType6 , class StateType7 , class Operation >
Chris@16 153 static void for_each7( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 ,
Chris@16 154 StateType5 &s5 , StateType6 &s6 , StateType7 &s7 , Operation op )
Chris@16 155 {
Chris@16 156 thrust::for_each(
Chris@16 157 thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
Chris@16 158 boost::begin(s2) ,
Chris@16 159 boost::begin(s3) ,
Chris@16 160 boost::begin(s4) ,
Chris@16 161 boost::begin(s5) ,
Chris@16 162 boost::begin(s6) ,
Chris@16 163 boost::begin(s7) ) ) ,
Chris@16 164 thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
Chris@16 165 boost::end(s2) ,
Chris@16 166 boost::end(s3) ,
Chris@16 167 boost::end(s4) ,
Chris@16 168 boost::end(s5) ,
Chris@16 169 boost::end(s6) ,
Chris@16 170 boost::end(s7) ) ) ,
Chris@16 171 op);
Chris@16 172 }
Chris@16 173
Chris@16 174 template< class StateType1 , class StateType2 , class StateType3 , class StateType4 ,
Chris@16 175 class StateType5 , class StateType6 , class StateType7 , class StateType8 , class Operation >
Chris@16 176 static void for_each8( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 ,
Chris@16 177 StateType5 &s5 , StateType6 &s6 , StateType7 &s7 , StateType8 &s8 , Operation op )
Chris@16 178 {
Chris@16 179 thrust::for_each(
Chris@16 180 thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
Chris@16 181 boost::begin(s2) ,
Chris@16 182 boost::begin(s3) ,
Chris@16 183 boost::begin(s4) ,
Chris@16 184 boost::begin(s5) ,
Chris@16 185 boost::begin(s6) ,
Chris@16 186 boost::begin(s7) ,
Chris@16 187 boost::begin(s8) ) ) ,
Chris@16 188 thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
Chris@16 189 boost::end(s2) ,
Chris@16 190 boost::end(s3) ,
Chris@16 191 boost::end(s4) ,
Chris@16 192 boost::end(s5) ,
Chris@16 193 boost::end(s6) ,
Chris@16 194 boost::end(s7) ,
Chris@16 195 boost::end(s8) ) ) ,
Chris@16 196 op);
Chris@16 197 }
Chris@16 198
Chris@101 199 template< class S >
Chris@101 200 static typename S::value_type norm_inf( const S &s )
Chris@16 201 {
Chris@101 202 typedef typename S::value_type value_type;
Chris@101 203 return thrust::reduce( boost::begin( s ) , boost::end( s ) ,
Chris@101 204 static_cast<value_type>(0) ,
Chris@101 205 detail::maximum<value_type>() );
Chris@16 206 }
Chris@16 207
Chris@16 208 };
Chris@16 209
Chris@16 210
Chris@16 211 } // odeint
Chris@16 212 } // numeric
Chris@16 213 } // boost
Chris@16 214
Chris@16 215
Chris@16 216
Chris@16 217 #endif // BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_ALGEBRA_HPP_INCLUDED