STIR 6.4.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*/
44
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
63START_NAMESPACE_STIR
64
65//----------------------------------------------------------------------
66// element wise and in place numeric functions
67//----------------------------------------------------------------------
68
70
71template <class elemT>
72inline Array<1, elemT>& in_place_log(Array<1, elemT>& v);
73
75
76template <int num_dimensions, class elemT>
77inline Array<num_dimensions, elemT>& in_place_log(Array<num_dimensions, elemT>& v);
78
80
81template <class elemT>
82inline Array<1, elemT>& in_place_exp(Array<1, elemT>& v);
83
85
86template <int num_dimensions, class elemT>
87inline Array<num_dimensions, elemT>& in_place_exp(Array<num_dimensions, elemT>& v);
88
90
93template <class elemT>
94inline Array<1, elemT>& in_place_abs(Array<1, elemT>& v);
95
97
100template <int num_dimensions, class elemT>
101inline Array<num_dimensions, elemT>& in_place_abs(Array<num_dimensions, elemT>& v);
102
104
113template <class T, class FUNCTION>
114inline T& in_place_apply_function(T& v, FUNCTION f);
115
117
144template <int num_dim, typename elemT, typename FunctionObjectPtr>
145inline void in_place_apply_array_function_on_1st_index(Array<num_dim, elemT>& array, FunctionObjectPtr f);
146
148
156template <int num_dim, typename elemT, typename FunctionObjectPtr>
157inline void
158apply_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
201template <int num_dim, typename elemT, typename FunctionObjectPtrIter>
202inline void in_place_apply_array_functions_on_each_index(Array<num_dim, elemT>& array,
203 FunctionObjectPtrIter start,
204 FunctionObjectPtrIter stop);
205
207template <typename elemT, typename FunctionObjectPtrIter>
208inline void
209in_place_apply_array_functions_on_each_index(Array<1, elemT>& array, FunctionObjectPtrIter start, FunctionObjectPtrIter stop);
210
212
226template <int num_dim, typename elemT, typename FunctionObjectPtrIter>
227inline 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
240template <int num_dim, typename elemT>
241inline 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
250template <typename elemT>
251inline 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
256template <typename elemT, typename FunctionObjectPtrIter>
258
260inline 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
265template <int num_dim, typename elemT>
266inline void transform_array_to_periodic_indices(Array<num_dim, elemT>& out_array, const Array<num_dim, elemT>& in_array);
267template <int num_dim, typename elemT>
268inline void transform_array_from_periodic_indices(Array<num_dim, elemT>& out_array, const Array<num_dim, elemT>& in_array);
269
270END_NAMESPACE_STIR
271
272#include "stir/ArrayFunction.inl"
273#undef ActualFunctionObjectPtrIter
274
275#endif
Declaration of class stir::ArrayFunctionObject.
Implementations for ArrayFunction.h.
defines the stir::Array class for multi-dimensional (numeric) arrays
Array< 1, elemT > & in_place_abs(Array< 1, elemT > &v)
Replace elements by their absolute value, 1D version.
Definition ArrayFunction.inl:82
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
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
void in_place_apply_array_functions_on_each_index(Array< num_dim, elemT > &array, FunctionObjectPtrIter start, FunctionObjectPtrIter stop)
Apply a sequence of 1d array-function objects on every dimension of the input array.
Definition ArrayFunction.inl:197
void apply_array_functions_on_each_index(Array< num_dim, elemT > &out_array, const Array< num_dim, elemT > &in_array, FunctionObjectPtrIter start, FunctionObjectPtrIter stop)
Apply a sequence of 1d array-function objects on every dimension of the input array,...
Definition ArrayFunction.inl:220
Array< 1, elemT > & in_place_exp(Array< 1, elemT > &v)
Replace elements by their exponentiation, 1D version.
Definition ArrayFunction.inl:64
Array< 1, elemT > & in_place_log(Array< 1, elemT > &v)
Replace elements by their logarithm, 1D version.
Definition ArrayFunction.inl:46
Import of std::shared_ptr, std::dynamic_pointer_cast and std::static_pointer_cast into the stir names...