10 #ifndef Shards_SimpleArrayOps_hpp
11 #define Shards_SimpleArrayOps_hpp
28 template<
unsigned n ,
unsigned i = 0 >
30 enum { N = n , I = i };
34 inline Copy( T *
const dst ,
const T *
const src )
35 { dst[I] = src[I] ;
Copy<N-1,I+1>(dst,src); }
39 inline Copy( T *
const dst ,
const T src )
40 { dst[I] = src ;
Copy<N-1,I+1>(dst,src); }
48 template<
unsigned n ,
unsigned i = 0 >
50 enum { N = n , I = i };
54 inline Sum( T *
const dst ,
const T *
const src )
55 { dst[I] += src[I] ;
Sum<N-1,I+1>(dst,src); }
59 inline Sum( T *
const dst ,
const T a ,
const T *
const src )
60 { dst[I] += a * src[I] ;
Sum<N-1,I+1>(dst,a,src); }
68 template<
unsigned n ,
unsigned i = 0 >
70 enum { N = n , I = i };
74 inline Prod( T *
const dst ,
const T *
const src )
75 { dst[I] *= src[I] ;
Prod<N-1,I+1>(dst,src); }
82 template<
unsigned n ,
unsigned i = 0 >
84 enum { N = n , I = i };
88 inline BitOr( T *
const dst ,
const T *
const src )
89 { dst[I] |= src[I] ;
BitOr<N-1,I+1>(dst,src); }
97 template<
unsigned n ,
unsigned i = 0 >
99 enum { N = n , I = i };
103 inline BitAnd( T *
const dst ,
const T *
const src )
104 { dst[I] &= src[I] ;
BitAnd<N-1,I+1>(dst,src); }
112 template<
unsigned n ,
unsigned i = 0 >
114 enum { N = n , I = i };
118 inline Max( T *
const dst ,
const T *
const src )
119 {
if ( dst[I] < src[I] ) { dst[I] = src[I] ; }
Max<N-1,I+1>(dst,src); }
127 template<
unsigned n ,
unsigned i = 0 >
129 enum { N = n , I = i };
133 inline Min( T *
const dst ,
const T *
const src )
134 {
if ( src[I] < dst[I] ) { dst[I] = src[I] ; }
Min<N-1,I+1>(dst,src); }
142 template<
unsigned n ,
unsigned i = 0 >
144 enum { N = n , I = i };
148 inline InnerProduct( T & value ,
const T *
const x ,
const T *
const y )
149 { value += x[I] * y[I] ;
InnerProduct<N-1,I+1>( value , x , y ); }
157 template<
unsigned n ,
unsigned i = 0 >
159 enum { N = n , I = i };
163 inline static bool equal(
const T *
const x ,
const T *
const y )
168 inline static bool not_equal(
const T *
const x ,
const T *
const y )
173 inline static bool less(
const T *
const x ,
const T *
const y )
180 inline static bool less_equal(
const T *
const x ,
const T *
const y )
187 inline static bool greater(
const T *
const x ,
const T *
const y )
206 #ifndef DOXYGEN_COMPILE
212 template<
typename T>
inline Copy( T *
const ,
const T *
const ) {}
213 template<
typename T>
inline Copy( T *
const ,
const T ) {}
220 template<
typename T>
inline Sum( T *
const ,
const T *
const ) {}
221 template<
typename T>
inline Sum( T *
const ,
const T ,
const T *
const ) {}
228 template<
typename T>
inline Prod( T *
const ,
const T *
const ) {}
235 template<
typename T>
inline Max( T *
const ,
const T *
const ) {}
242 template<
typename T>
inline Min( T *
const ,
const T *
const ) {}
249 template<
typename T>
inline BitOr( T *
const ,
const T *
const ) {}
256 template<
typename T>
inline BitAnd( T *
const ,
const T *
const ) {}
260 struct InnerProduct<0,i> {
264 inline InnerProduct( T & ,
const T *
const ,
const T *
const ) {}
268 struct Compare<0,i> {
273 inline static bool equal(
const T *
const ,
const T *
const )
277 inline static bool not_equal(
const T *
const ,
const T *
const )
281 inline static bool less(
const T *
const ,
const T *
const )
285 inline static bool less_equal(
const T *
const ,
const T *
const )
289 inline static bool greater(
const T *
const ,
const T *
const )
293 inline static bool greater_equal(
const T *
const ,
const T *
const )
static bool greater(const T *const x, const T *const y)
First non-equal members satisfies x[k] > y[k].
Min(T *const dst, const T *const src)
dst[0..N-1] = min( dst[0..N-1] , src[0..N-1] )
BitOr(T *const dst, const T *const src)
dst[0..N-1] |= src[0..N-1]
Bitwise-or into an array.
Take maximum value of each member of two arrays.
static bool not_equal(const T *const x, const T *const y)
All members are not equal.
static bool less_equal(const T *const x, const T *const y)
First non-equal members satisfies x[k] <= y[k].
Take minimum value of each member of two arrays.
Copy(T *const dst, const T *const src)
dst[0..N-1] = src[0..N-1]
Copy(T *const dst, const T src)
dst[0..N-1] = src
Inner product of two arrays.
static bool greater_equal(const T *const x, const T *const y)
First non-equal members satisfies x[k] >= y[k].
Lexicographical comparison of two arrays.
static bool less(const T *const x, const T *const y)
First non-equal members satisfy x[k] < y[k].
BitAnd(T *const dst, const T *const src)
dst[0..N-1] &= src[0..N-1]
InnerProduct(T &value, const T *const x, const T *const y)
value += sum[ k = 0..N-1 ]( x[k] * y[k] )
Sum(T *const dst, const T *const src)
dst[0..N-1] += src[0..N-1]
static bool equal(const T *const x, const T *const y)
All members are equal.
Prod(T *const dst, const T *const src)
dst[0..N-1] *= src[0..N-1]
Bitwise-and into an array.
Sum(T *const dst, const T a, const T *const src)
dst[0..N-1] += a * src[0..N-1]
Max(T *const dst, const T *const src)
dst[0..N-1] = max( dst[0..N-1] , src[0..N-1] )