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