STIR  6.2.0
ArrayFunction.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2000 PARAPET partners
3  Copyright (C) 2000- 2007, Hammersmith Imanet Ltd
4  This file is part of STIR.
5 
6  SPDX-License-Identifier: Apache-2.0 AND License-ref-PARAPET-license
7 
8  See STIR/LICENSE.txt for details
9 */
45 /* History:
46 
47  KT 21/05/2001
48  added in_place_apply_array_function_on_1st_index,
49  in_place_apply_array_function_on_each_index
50 
51  KT 06/12/2001
52  added apply_array_function_on_1st_index,
53  apply_array_function_on_each_index
54 */
55 
56 #ifndef __stir_ArrayFunction_H__
57 #define __stir_ArrayFunction_H__
58 
59 #include "stir/Array.h"
60 #include "stir/shared_ptr.h"
62 
63 START_NAMESPACE_STIR
64 
65 //----------------------------------------------------------------------
66 // element wise and in place numeric functions
67 //----------------------------------------------------------------------
68 
70 
71 template <class elemT>
72 inline Array<1, elemT>& in_place_log(Array<1, elemT>& v);
73 
75 
76 template <int num_dimensions, class elemT>
77 inline Array<num_dimensions, elemT>& in_place_log(Array<num_dimensions, elemT>& v);
78 
80 
81 template <class elemT>
82 inline Array<1, elemT>& in_place_exp(Array<1, elemT>& v);
83 
85 
86 template <int num_dimensions, class elemT>
87 inline Array<num_dimensions, elemT>& in_place_exp(Array<num_dimensions, elemT>& v);
88 
90 
93 template <class elemT>
94 inline Array<1, elemT>& in_place_abs(Array<1, elemT>& v);
95 
97 
100 template <int num_dimensions, class elemT>
101 inline Array<num_dimensions, elemT>& in_place_abs(Array<num_dimensions, elemT>& v);
102 
104 
113 template <class T, class FUNCTION>
114 inline T& in_place_apply_function(T& v, FUNCTION f);
115 
117 
144 template <int num_dim, typename elemT, typename FunctionObjectPtr>
145 inline void in_place_apply_array_function_on_1st_index(Array<num_dim, elemT>& array, FunctionObjectPtr f);
146 
148 
156 template <int num_dim, typename elemT, typename FunctionObjectPtr>
157 inline void
158 apply_array_function_on_1st_index(Array<num_dim, elemT>& out_array, const Array<num_dim, elemT>& in_array, FunctionObjectPtr f);
159 
160 /* local #define used for 2 purposes:
161  - in partial template specialisation that uses ArrayFunctionObject types
162  - in complete template specialisation for deficient compilers
163 
164  This is done with a #define to keep code reasonably clean. Also, it allows
165  adjusting the type according to what you need.
166  Still, it's terribly ugly. Sorry.
167 
168  Note that you shouldn't/cannot use this define outside of this include file
169  (and its .inl) partner.
170 
171  Ideally, the code should be rewritten to work with any kind of (smart) ptr. TODO
172 */
173 #if !defined(__GNUC__) && !defined(_MSC_VER)
174 # define ActualFunctionObjectPtrIter VectorWithOffset<shared_ptr<ArrayFunctionObject<1, elemT>>>::const_iterator
175 #else
176 /*
177  Puzzlingly, although the code is actually called with iterators of the type above,
178  gcc 3.0 (and others?) gets confused and refuses to compile the
179  partial template specialisation (it says it's ambiguous).
180  VC also refuses to compile it.
181  A work-around is to use the following type
182 */
183 # define ActualFunctionObjectPtrIter shared_ptr<ArrayFunctionObject<1, elemT>> const*
184 #endif
185 
187 
200 // TODO add specialisation that uses ArrayFunctionObject::is_trivial
201 template <int num_dim, typename elemT, typename FunctionObjectPtrIter>
202 inline void in_place_apply_array_functions_on_each_index(Array<num_dim, elemT>& array,
203  FunctionObjectPtrIter start,
204  FunctionObjectPtrIter stop);
205 
207 template <typename elemT, typename FunctionObjectPtrIter>
208 inline void
209 in_place_apply_array_functions_on_each_index(Array<1, elemT>& array, FunctionObjectPtrIter start, FunctionObjectPtrIter stop);
210 
212 
226 template <int num_dim, typename elemT, typename FunctionObjectPtrIter>
227 inline void apply_array_functions_on_each_index(Array<num_dim, elemT>& out_array,
228  const Array<num_dim, elemT>& in_array,
229  FunctionObjectPtrIter start,
230  FunctionObjectPtrIter stop);
231 
233 
240 template <int num_dim, typename elemT>
241 inline void apply_array_functions_on_each_index(Array<num_dim, elemT>& out_array,
242  const Array<num_dim, elemT>& in_array,
243  ActualFunctionObjectPtrIter start,
244  ActualFunctionObjectPtrIter stop);
245 
247 
249 // has to be here to get general 1D specialisation to compile
250 template <typename elemT>
251 inline void apply_array_functions_on_each_index(Array<1, elemT>& out_array,
252  const Array<1, elemT>& in_array,
253  ActualFunctionObjectPtrIter start,
254  ActualFunctionObjectPtrIter stop);
255 
256 template <typename elemT, typename FunctionObjectPtrIter>
258 
260 inline void apply_array_functions_on_each_index(Array<1, elemT>& out_array,
261  const Array<1, elemT>& in_array,
262  FunctionObjectPtrIter start,
263  FunctionObjectPtrIter stop);
264 
265 template <int num_dim, typename elemT>
266 inline void transform_array_to_periodic_indices(Array<num_dim, elemT>& out_array, const Array<num_dim, elemT>& in_array);
267 template <int num_dim, typename elemT>
268 inline void transform_array_from_periodic_indices(Array<num_dim, elemT>& out_array, const Array<num_dim, elemT>& in_array);
269 
270 END_NAMESPACE_STIR
271 
272 #include "stir/ArrayFunction.inl"
273 #undef ActualFunctionObjectPtrIter
274 
275 #endif
Array< num_dimensions, elemT > & in_place_log(Array< num_dimensions, elemT > &v)
apply log to each element of the multi-dimensional array
Definition: ArrayFunction.inl:55
void in_place_apply_array_function_on_1st_index(Array< num_dim, elemT > &array, FunctionObjectPtr f)
Apply a function object on all possible 1d arrays extracted by keeping all indices fixed...
Definition: ArrayFunction.inl:115
T & in_place_apply_function(T &v, FUNCTION f)
apply any function(object) to each element of the multi-dimensional array
Definition: ArrayFunction.inl:101
Array< num_dimensions, elemT > & in_place_exp(Array< num_dimensions, elemT > &v)
apply exp to each element of the multi-dimensional array
Definition: ArrayFunction.inl:73
Import of std::shared_ptr, std::dynamic_pointer_cast and std::static_pointer_cast (or corresponding b...
defines the Array class for multi-dimensional (numeric) arrays
void apply_array_function_on_1st_index(Array< num_dim, elemT > &out_array, const Array< num_dim, elemT > &in_array, FunctionObjectPtr f)
apply any function(object) to each element of the multi-dimensional array, storing results in a diffe...
Definition: ArrayFunction.inl:152
Array< num_dimensions, elemT > & in_place_abs(Array< num_dimensions, elemT > &v)
store absolute value of each element of the multi-dimensional array
Definition: ArrayFunction.inl:92
void in_place_apply_array_functions_on_each_index(Array< 1, elemT > &array, FunctionObjectPtrIter start, FunctionObjectPtrIter stop)
1d specialisation of the above.
Definition: ArrayFunction.inl:212
Declaration of class stir::ArrayFunctionObject.
Implementations for ArrayFunction.h.
void apply_array_functions_on_each_index(Array< 1, elemT > &out_array, const Array< 1, elemT > &in_array, FunctionObjectPtrIter start, FunctionObjectPtrIter stop)
1d specialisation for general function objects
Definition: ArrayFunction.inl:301