Loading...
Searching...
No Matches
IterationUtils-Impl.hpp
Go to the documentation of this file.
1// This code is based on Jet framework.
2// Copyright (c) 2018 Doyub Kim
3// CubbyFlow is voxel-based fluid simulation engine for computer games.
4// Copyright (c) 2020 CubbyFlow Team
5// Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo
6// AI Part: Dongheon Cho, Minseo Kim
7// We are making my contributions/submissions to this project solely in our
8// personal capacity and are not conveying any rights to any intellectual
9// property of any third parties.
10
11#ifndef CUBBYFLOW_ITERATION_UTILS_IMPL_HPP
12#define CUBBYFLOW_ITERATION_UTILS_IMPL_HPP
13
14namespace CubbyFlow
15{
16namespace Internal
17{
18template <typename IndexType, size_t N, size_t I>
20{
21 template <typename Func, typename... RemainingIndices>
22 static void Call(const Vector<IndexType, N>& begin,
23 const Vector<IndexType, N>& end, const Func& func,
25 {
26 for (IndexType i = begin[I - 1]; i < end[I - 1]; ++i)
27 {
29 indices...);
30 }
31 }
32};
33
34template <typename IndexType, size_t N>
36{
37 template <typename Func, typename... RemainingIndices>
38 static void Call(const Vector<IndexType, N>& begin,
39 const Vector<IndexType, N>& end, const Func& func,
41 {
42 for (IndexType i = begin[0]; i < end[0]; ++i)
43 {
44 func(i, indices...);
45 }
46 }
47};
48} // namespace Internal
49
50template <typename IndexType, size_t N, typename Func>
52 const Vector<IndexType, N>& end, const Func& func)
53{
54 for (IndexType i = begin[N - 1]; i < end[N - 1]; ++i)
55 {
57 }
58}
59
60template <typename IndexType, typename Func>
62 const Vector<IndexType, 1>& end, const Func& func)
63{
64 for (IndexType i = begin[0]; i < end[0]; ++i)
65 {
66 func(i);
67 }
68}
69
70template <typename IndexType, typename Func>
71void ForEachIndex(IndexType begin, IndexType end, const Func& func)
72{
73 for (IndexType i = begin; i < end; ++i)
74 {
75 func(i);
76 }
77}
78
79template <typename IndexType, size_t N, typename Func>
84
85template <typename IndexType, typename Func>
90
91template <typename IndexType, typename Func>
96
97template <typename IndexType, size_t N, typename Func>
99 const Vector<IndexType, N>& end, const Func& func,
101{
103 begin[N - 1], end[N - 1],
104 [&](IndexType i) {
106 i);
107 },
108 policy);
109}
110
111template <typename IndexType, typename Func>
113 const Vector<IndexType, 1>& end, const Func& func,
115{
116 ParallelFor(begin[0], end[0], func, policy);
117}
118
119template <typename IndexType, typename Func>
122{
123 ParallelFor(begin, end, func, policy);
124}
125
126template <typename IndexType, size_t N, typename Func>
132
133template <typename IndexType, typename Func>
139
140template <typename IndexType, typename Func>
146} // namespace CubbyFlow
147
148#endif
Definition Matrix.hpp:30
Definition pybind11Utils.hpp:21
void ForEachIndex(const Vector< IndexType, N > &begin, const Vector< IndexType, N > &end, const Func &func)
Definition IterationUtils-Impl.hpp:51
void ParallelFor(IndexType beginIndex, IndexType endIndex, const Function &function, ExecutionPolicy policy)
Makes a for-loop from beginIndex to endIndex in parallel.
Definition Parallel-Impl.hpp:212
Matrix< T, Rows, 1 > Vector
Definition Matrix.hpp:738
void ParallelForEachIndex(const Vector< IndexType, N > &begin, const Vector< IndexType, N > &end, const Func &func, ExecutionPolicy policy)
Definition IterationUtils-Impl.hpp:98
ExecutionPolicy
Execution policy tag.
Definition Parallel.hpp:18
static void Call(const Vector< IndexType, N > &begin, const Vector< IndexType, N > &end, const Func &func, RemainingIndices... indices)
Definition IterationUtils-Impl.hpp:38
Definition IterationUtils-Impl.hpp:20
static void Call(const Vector< IndexType, N > &begin, const Vector< IndexType, N > &end, const Func &func, RemainingIndices... indices)
Definition IterationUtils-Impl.hpp:22