AFF --- A container for numbers (array) by Friederich and Forbriger.
rawarfun.h
Go to the documentation of this file.
1 
46 // include guard
47 #ifndef AFF_RAWARFUN_H_VERSION
48 
49 #define AFF_RAWARFUN_H_VERSION \
50  "AFF_RAWARFUN_H V1.3"
51 
52 #include<aff/lib/types.h>
53 
54 namespace aff {
55 
56 namespace util {
57 
59  template<typename T, int I>
60  class Inline {
61  public:
63  static inline void copy(const T* source, T* target)
64  {
65  target[I-1]=source[I-1];
66  Inline<T,I-1>::copy(source, target);
67  }
73  static inline T product(const T* array)
74  {
75  return(array[I-1]*Inline<T,I-1>::product(array));
76  }
82  static inline T sum(const T* array)
83  {
84  return(array[I-1]+Inline<T,I-1>::sum(array));
85  }
87  static inline void set(T* array, const T& value)
88  {
89  array[I-1]=value; Inline<T,I-1>::set(array, value);
90  }
92  static inline bool anysmaller(const T* A, const T* B)
93  {
94  return (((*A) < (*B))
95  || Inline<T,I-1>::anysmaller(&(A[1]), &(B[1])));
96  }
98  static inline bool anylarger(const T* A, const T* B)
99  {
100  return (((*A) > (*B))
101  || Inline<T,I-1>::anylarger(&(A[1]), &(B[1])));
102  }
109  static inline T innerproduct(const T* A, const T* B)
110  {
111  return(A[I-1]*B[I-1]+Inline<T, I-1>::innerproduct(A,B));
112  }
128  static inline T strideproduct(const T* A, const T* B)
129  {
130  return((*A)+(*B)*Inline<T, I-1>::strideproduct(&(A[1]),&(B[1])));
131  }
132  }; // class Inline
133 
135  template<typename T>
136  class Inline<T,1> {
137  public:
138  static inline void copy(const T* source, T* target)
139  { target[0]=source[0]; }
140  static inline T product(const T* array)
141  { return (array[0]); }
142  static inline T sum(const T* array)
143  { return (array[0]); }
144  static inline void set(T* array, const T& value)
145  { array[0]=value; }
146  static inline bool anysmaller(const T* A, const T* B)
147  { return (((*A) < (*B))); }
148  static inline bool anylarger(const T* A, const T* B)
149  { return (((*A) > (*B))); }
150  static inline T innerproduct(const T* A, const T* B)
151  { return(A[0]*B[0]); }
152  static inline T strideproduct(const T* A, const T* B)
153  { return(A[0]+B[0]); }
154  }; // class Inline<T, 1>
155 
156  /*----------------------------------------------------------------------*/
157 
159  template<typename T1, typename T2, int I>
160  class Inline2 {
161  public:
163  static inline void copy(const T1* source, T2* target)
164  {
165  target[I-1]=source[I-1];
166  Inline2<T1, T2, I-1>::copy(source, target);
167  }
169  static inline void set(T1* array, const T2& value)
170  {
171  array[I-1]=value; Inline2<T1, T2 ,I-1>::set(array, value);
172  }
174  static inline bool anysmaller(const T1* A, const T2* B)
175  {
176  return (((*A) < (*B))
177  || Inline2<T1, T2, I-1>::anysmaller(&(A[1]), &(B[1])));
178  }
180  static inline bool anylarger(const T1* A, const T2* B)
181  {
182  return (((*A) > (*B))
183  || Inline2<T1, T2,I-1>::anylarger(&(A[1]), &(B[1])));
184  }
191  static inline T1 innerproduct(const T1* A, const T2* B)
192  {
193  return(A[I-1]*B[I-1]+Inline2<T1, T2, I-1>::innerproduct(A,B));
194  }
210  static inline T1 strideproduct(const T1* A, const T2* B)
211  {
212  return((*A)+(*B)*Inline2<T1, T2, I-1>::strideproduct(&(A[1]),&(B[1])));
213  }
214  }; // class Inline2
215 
217  template<typename T1, typename T2>
218  class Inline2<T1, T2, 1> {
219  public:
220  static inline void copy(const T1* source, T2* target)
221  { target[0]=source[0]; }
222  static inline void set(T1* array, const T2& value)
223  { array[0]=value; }
224  static inline bool anysmaller(const T1* A, const T2* B)
225  { return (((*A) < (*B))); }
226  static inline bool anylarger(const T1* A, const T2* B)
227  { return (((*A) > (*B))); }
228  static inline T1 innerproduct(const T1* A, const T2* B)
229  { return(A[0]*B[0]); }
230  static inline T1 strideproduct(const T1* A, const T2* B)
231  { return(A[0]+B[0]); }
232  }; // class Inline2<T1, T2, 1>
233 
234 } // namespace util
235 
236 } // namespace aff
237 
238 #endif // AFF_RAWARFUN_H_VERSION (includeguard)
239 
240 /* ----- END OF rawarfun.h ----- */
Root namespace of library.
Definition: array.h:148
some typedefs we refer to
static void copy(const T *source, T *target)
copy all values from source to target
Definition: rawarfun.h:63
Recursive functions to inline raw array operations.
Definition: rawarfun.h:160
static T innerproduct(const T *A, const T *B)
Definition: rawarfun.h:150
static T product(const T *array)
calculate product of all elements
Definition: rawarfun.h:73
static bool anysmaller(const T1 *A, const T2 *B)
true if ony of A is smaller than corresponding B
Definition: rawarfun.h:174
static void copy(const T *source, T *target)
Definition: rawarfun.h:138
static bool anysmaller(const T *A, const T *B)
Definition: rawarfun.h:146
static T innerproduct(const T *A, const T *B)
calculate inner product
Definition: rawarfun.h:109
static bool anylarger(const T1 *A, const T2 *B)
Definition: rawarfun.h:226
static void set(T1 *array, const T2 &value)
set all elements to value
Definition: rawarfun.h:169
static T1 innerproduct(const T1 *A, const T2 *B)
Definition: rawarfun.h:228
static bool anylarger(const T1 *A, const T2 *B)
true if ony of A is larger than corresponding B
Definition: rawarfun.h:180
Recursive functions to inline raw array operations.
Definition: rawarfun.h:60
static T strideproduct(const T *A, const T *B)
Definition: rawarfun.h:152
static bool anylarger(const T *A, const T *B)
Definition: rawarfun.h:148
static void copy(const T1 *source, T2 *target)
copy all values from source to target
Definition: rawarfun.h:163
static void set(T *array, const T &value)
set all elements to value
Definition: rawarfun.h:87
static T1 strideproduct(const T1 *A, const T2 *B)
calculate stride product
Definition: rawarfun.h:210
static void copy(const T1 *source, T2 *target)
Definition: rawarfun.h:220
static T1 strideproduct(const T1 *A, const T2 *B)
Definition: rawarfun.h:230
static bool anylarger(const T *A, const T *B)
true if ony of A is larger than corresponding B
Definition: rawarfun.h:98
static bool anysmaller(const T *A, const T *B)
true if ony of A is smaller than corresponding B
Definition: rawarfun.h:92
static T sum(const T *array)
Definition: rawarfun.h:142
static T strideproduct(const T *A, const T *B)
calculate stride product
Definition: rawarfun.h:128
static bool anysmaller(const T1 *A, const T2 *B)
Definition: rawarfun.h:224
static T1 innerproduct(const T1 *A, const T2 *B)
calculate inner product
Definition: rawarfun.h:191
static T sum(const T *array)
calculate sum of all elements
Definition: rawarfun.h:82
static T product(const T *array)
Definition: rawarfun.h:140