| 42 | |
| 43 | template<typename T> |
| 44 | void replaceTest(const dim4 &dims) { |
| 45 | SUPPORTED_TYPE_CHECK(T); |
| 46 | dtype ty = (dtype)dtype_traits<T>::af_type; |
| 47 | |
| 48 | array a = randu(dims, ty); |
| 49 | array b = randu(dims, ty); |
| 50 | |
| 51 | if (a.isinteger()) { |
| 52 | a = (a % (1 << 30)).as(ty); |
| 53 | b = (b % (1 << 30)).as(ty); |
| 54 | } |
| 55 | |
| 56 | array c = a.copy(); |
| 57 | |
| 58 | array cond = randu(dims, ty) > a; |
| 59 | |
| 60 | replace(c, cond, b); |
| 61 | |
| 62 | int num = (int)a.elements(); |
| 63 | |
| 64 | vector<T> ha(num); |
| 65 | vector<T> hb(num); |
| 66 | vector<T> hc(num); |
| 67 | vector<char> hcond(num); |
| 68 | |
| 69 | a.host(&ha[0]); |
| 70 | b.host(&hb[0]); |
| 71 | c.host(&hc[0]); |
| 72 | cond.host(&hcond[0]); |
| 73 | |
| 74 | for (int i = 0; i < num; i++) { |
| 75 | ASSERT_EQ(hc[i], hcond[i] ? ha[i] : hb[i]); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | template<typename T> |
| 80 | void replaceScalarTest(const dim4 &dims) { |