46 #ifndef Shards_SimpleArrayOps_hpp
47 #define Shards_SimpleArrayOps_hpp
64 template<
unsigned n ,
unsigned i = 0 >
66 enum { N = n , I = i };
70 inline Copy( T *
const dst ,
const T *
const src )
71 { dst[I] = src[I] ;
Copy<N-1,I+1>(dst,src); }
75 inline Copy( T *
const dst ,
const T src )
76 { dst[I] = src ;
Copy<N-1,I+1>(dst,src); }
84 template<
unsigned n ,
unsigned i = 0 >
86 enum { N = n , I = i };
90 inline Sum( T *
const dst ,
const T *
const src )
91 { dst[I] += src[I] ;
Sum<N-1,I+1>(dst,src); }
95 inline Sum( T *
const dst ,
const T a ,
const T *
const src )
96 { dst[I] += a * src[I] ;
Sum<N-1,I+1>(dst,a,src); }
104 template<
unsigned n ,
unsigned i = 0 >
106 enum { N = n , I = i };
110 inline Prod( T *
const dst ,
const T *
const src )
111 { dst[I] *= src[I] ;
Prod<N-1,I+1>(dst,src); }
118 template<
unsigned n ,
unsigned i = 0 >
120 enum { N = n , I = i };
124 inline BitOr( T *
const dst ,
const T *
const src )
125 { dst[I] |= src[I] ;
BitOr<N-1,I+1>(dst,src); }
133 template<
unsigned n ,
unsigned i = 0 >
135 enum { N = n , I = i };
139 inline BitAnd( T *
const dst ,
const T *
const src )
140 { dst[I] &= src[I] ;
BitAnd<N-1,I+1>(dst,src); }
148 template<
unsigned n ,
unsigned i = 0 >
150 enum { N = n , I = i };
154 inline Max( T *
const dst ,
const T *
const src )
155 {
if ( dst[I] < src[I] ) { dst[I] = src[I] ; }
Max<N-1,I+1>(dst,src); }
163 template<
unsigned n ,
unsigned i = 0 >
165 enum { N = n , I = i };
169 inline Min( T *
const dst ,
const T *
const src )
170 {
if ( src[I] < dst[I] ) { dst[I] = src[I] ; }
Min<N-1,I+1>(dst,src); }
178 template<
unsigned n ,
unsigned i = 0 >
180 enum { N = n , I = i };
184 inline InnerProduct( T & value ,
const T *
const x ,
const T *
const y )
185 { value += x[I] * y[I] ;
InnerProduct<N-1,I+1>( value , x , y ); }
193 template<
unsigned n ,
unsigned i = 0 >
195 enum { N = n , I = i };
199 inline static bool equal(
const T *
const x ,
const T *
const y )
204 inline static bool not_equal(
const T *
const x ,
const T *
const y )
209 inline static bool less(
const T *
const x ,
const T *
const y )
216 inline static bool less_equal(
const T *
const x ,
const T *
const y )
223 inline static bool greater(
const T *
const x ,
const T *
const y )
242 #ifndef DOXYGEN_COMPILE
248 template<
typename T>
inline Copy( T *
const ,
const T *
const ) {}
249 template<
typename T>
inline Copy( T *
const ,
const T ) {}
256 template<
typename T>
inline Sum( T *
const ,
const T *
const ) {}
257 template<
typename T>
inline Sum( T *
const ,
const T ,
const T *
const ) {}
264 template<
typename T>
inline Prod( T *
const ,
const T *
const ) {}
271 template<
typename T>
inline Max( T *
const ,
const T *
const ) {}
278 template<
typename T>
inline Min( T *
const ,
const T *
const ) {}
285 template<
typename T>
inline BitOr( T *
const ,
const T *
const ) {}
292 template<
typename T>
inline BitAnd( T *
const ,
const T *
const ) {}
296 struct InnerProduct<0,i> {
300 inline InnerProduct( T & ,
const T *
const ,
const T *
const ) {}
304 struct Compare<0,i> {
309 inline static bool equal(
const T *
const ,
const T *
const )
313 inline static bool not_equal(
const T *
const ,
const T *
const )
317 inline static bool less(
const T *
const ,
const T *
const )
321 inline static bool less_equal(
const T *
const ,
const T *
const )
325 inline static bool greater(
const T *
const ,
const T *
const )
329 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] )