FiberVISH 0.2
Fish - The Fiber Bundle API for the Vish Visualization Shell
TypedArrayOperations.hpp
1#ifndef __FIBER_TYPEDARRAYOPERATIONS_HPP
2#define __FIBER_TYPEDARRAYOPERATIONS_HPP
3
4#include "TypedArray.hpp"
5#include <functional>
6
7namespace Fiber
8{
9
22template <class Result_t, class T>
23bool applyFunctor(const TypedArray<Result_t>&Result, const TypedArray<T>&Data, const std::function<Result_t(const T&)>&func)
24{
25const CreativeIterator<T>*C = Data.creativeIterator();
26 if (!C) return false;
27const CreativeIterator<T>&CL = *C;
28
29const CreativeIterator<Result_t>*CRes = Result.creativeIterator();
30 if (!CRes) return false;
32
33 if (CL.count() != Res.count() )
34 return false;
35
36 for(index_t i=0; i<CL.count(); i++)
37 {
38 const T&in = CL[i];
39 Result_t&out = Res[i];
40 out = func( in );
41 }
42 return true;
43}
44
49template <class Result_t, class T>
50bool applyFunctor(const TypedArray<Result_t>&Result, const TypedArray<T>&Data, const std::function<Result_t(index_t i, const T&)>&func)
51{
52const CreativeIterator<T>*C = Data.creativeIterator();
53 if (!C) return false;
54const CreativeIterator<T>&CL = *C;
55
56const CreativeIterator<Result_t>*CRes = Result.creativeIterator();
57 if (!CRes) return false;
59
60 if (CL.count() != Res.count() )
61 return false;
62
63 for(index_t i=0; i<CL.count(); i++)
64 {
65 const T&in = CL[i];
66 Result_t&out = Res[i];
67 out = func(i, in );
68 }
69 return true;
70}
71
72
76template <class Result_t, class T, class Operand_t>
78 const std::function<Result_t(const T&, const Operand_t&)>&func)
79{
80const CreativeIterator<T>*C = L.creativeIterator();
81 if (!C) return false;
82const CreativeIterator<T>&CL = *C;
83
84const CreativeIterator<Operand_t>*CR = R.creativeIterator();
85 if (!CR)return false;
86
88 if (CL.count() != CIR.count() )
89 return false;
90
91const CreativeIterator<Result_t>*CRes = Result.creativeIterator();
92 if (!CRes) return false;
93
95
96 if (CL.count() != Res.count() )
97 return false;
98
99 for(index_t i=0; i<CL.count(); i++)
100 {
101 const T&in = C[i];
102 const Operand_t&inR = CIR[i];
103 Result_t&out = Result[i];
104 out = func( in, inR );
105 }
106 return true;
107}
108
109} // namespace
110
111
112#endif // __FIBER_TYPEDARRAYOPERATIONS_HPP
An iterator with an optional DataCreator, which is just a class to intercept creation of data along a...
Definition CreativeIterator.hpp:34
index_t count() const
Return the number of steps which can be traversed through this ElementIterator.
Definition HyperslabParameters.hpp:147
Given a fragmented field of curvilinear coordinates, (3D array of coordinates), build a uniform Grid ...
Definition FAQ.dox:2
bool applyFunctor(const TypedArray< Result_t > &Result, const TypedArray< T > &Data, const std::function< Result_t(const T &)> &func)
Apply a unary functor to a TypedArray.
Definition TypedArrayOperations.hpp:23
IndexTypeConfig< sizeof(void *)>::index_t index_t
Define the index type as according to the size of a pointer, i.e.
Definition Index.hpp:22