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

Function replaceScalarTest

test/replace.cpp:80–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78
79template<typename T>
80void replaceScalarTest(const dim4 &dims) {
81 SUPPORTED_TYPE_CHECK(T);
82 using scalar_t =
83 typename std::conditional<std::is_same<T, intl>::value ||
84 std::is_same<T, uintl>::value,
85 T, double>::type;
86
87 dtype ty = (dtype)dtype_traits<T>::af_type;
88
89 array a = randu(dims, ty);
90
91 if (a.isinteger()) { a = (a % (1 << 30)).as(ty); }
92
93 array c = a.copy();
94 array cond = randu(dims, ty) > a;
95 scalar_t b = static_cast<scalar_t>(3);
96
97 replace(c, cond, b);
98 int num = (int)a.elements();
99
100 vector<T> ha(num);
101 vector<T> hc(num);
102 vector<char> hcond(num);
103
104 a.host(&ha[0]);
105 c.host(&hc[0]);
106 cond.host(&hcond[0]);
107
108 for (int i = 0; i < num; i++) { ASSERT_EQ(hc[i], hcond[i] ? ha[i] : T(b)); }
109}
110
111TYPED_TEST(Replace, Simple) { replaceTest<TypeParam>(dim4(1024, 1024)); }
112

Callers

nothing calls this directly

Calls 6

randuFunction · 0.85
asMethod · 0.80
hostMethod · 0.80
replaceFunction · 0.50
copyMethod · 0.45
elementsMethod · 0.45

Tested by

no test coverage detected