| 78 | |
| 79 | template<typename T> |
| 80 | void 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 | |
| 111 | TYPED_TEST(Replace, Simple) { replaceTest<TypeParam>(dim4(1024, 1024)); } |
| 112 | |