-
Notifications
You must be signed in to change notification settings - Fork 6
/
logical.cpp
50 lines (41 loc) · 1.3 KB
/
logical.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "logical.h"
bool TRTC_All_Of(const DVVectorLike& vec, const Functor& pred, bool& ret)
{
static TRTC_For s_for({ "view_vec", "view_res", "pred" }, "idx",
" if (!pred(view_vec[idx])) view_res[0]=false;\n"
);
ret = false;
if (vec.size() < 1) return true;
ret = true;
DVVector dvres("bool", 1, &ret);
const DeviceViewable* args[] = { &vec, &dvres, &pred };
if (!s_for.launch_n(vec.size(), args)) return false;
dvres.to_host(&ret);
return true;
}
bool TRTC_Any_Of(const DVVectorLike& vec, const Functor& pred, bool& ret)
{
static TRTC_For s_for({ "view_vec", "view_res", "pred" }, "idx",
" if (pred(view_vec[idx])) view_res[0]=true;\n"
);
ret = false;
if (vec.size() < 1) return true;
DVVector dvres("bool", 1, &ret);
const DeviceViewable* args[] = { &vec, &dvres, &pred };
if (!s_for.launch_n(vec.size(), args)) return false;
dvres.to_host(&ret);
return true;
}
bool TRTC_None_Of(const DVVectorLike& vec, const Functor& pred, bool& ret)
{
static TRTC_For s_for({ "view_vec", "view_res", "pred" }, "idx",
" if (pred(view_vec[idx])) view_res[0]=false;\n"
);
ret = true;
if (vec.size() < 1) return true;
DVVector dvres("bool", 1, &ret);
const DeviceViewable* args[] = { &vec, &dvres, &pred };
if (!s_for.launch_n(vec.size(), args)) return false;
dvres.to_host(&ret);
return true;
}