MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / selectScalarTest

Function selectScalarTest

test/select.cpp:84–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

82
83template<typename T, bool is_right>
84void selectScalarTest(const dim4& dims) {
85 SUPPORTED_TYPE_CHECK(T);
86 using scalar_t =
87 typename std::conditional<std::is_same<T, intl>::value ||
88 std::is_same<T, uintl>::value,
89 T, double>::type;
90
91 dtype ty = (dtype)dtype_traits<T>::af_type;
92
93 array a = randu(dims, ty);
94 array cond = randu(dims, ty) > a;
95 scalar_t b = static_cast<scalar_t>(3);
96
97 if (a.isinteger()) { a = (a % (1 << 30)).as(ty); }
98
99 array c = is_right ? select(cond, a, b) : select(cond, b, a);
100
101 int num = (int)a.elements();
102
103 vector<T> ha(num);
104 vector<T> hc(num);
105 vector<char> hcond(num);
106
107 a.host(&ha[0]);
108 c.host(&hc[0]);
109 cond.host(&hcond[0]);
110
111 if (is_right) {
112 for (int i = 0; i < num; i++) {
113 ASSERT_EQ(hc[i], hcond[i] ? ha[i] : T(b));
114 }
115 } else {
116 for (int i = 0; i < num; i++) {
117 ASSERT_EQ(hc[i], hcond[i] ? T(b) : ha[i]);
118 }
119 }
120}
121
122TYPED_TEST(Select, Simple) { selectTest<TypeParam>(dim4(1024, 1024)); }
123

Callers

nothing calls this directly

Calls 5

randuFunction · 0.85
asMethod · 0.80
hostMethod · 0.80
selectFunction · 0.50
elementsMethod · 0.45

Tested by

no test coverage detected