| 50 | class Clamp : public ::testing::TestWithParam<clamp_params> { |
| 51 | public: |
| 52 | void SetUp() { |
| 53 | clamp_params params = GetParam(); |
| 54 | SUPPORTED_TYPE_CHECK(double); |
| 55 | if (noDoubleTests(params.in_type_)) |
| 56 | GTEST_SKIP() << "Double not supported on this device"; |
| 57 | if (noHalfTests(params.in_type_)) |
| 58 | GTEST_SKIP() << "Half not supported on this device"; |
| 59 | if (noDoubleTests(params.hi_type_)) |
| 60 | GTEST_SKIP() << "Double not supported on this device"; |
| 61 | if (noHalfTests(params.hi_type_)) |
| 62 | GTEST_SKIP() << "Half not supported on this device"; |
| 63 | if (noDoubleTests(params.lo_type_)) |
| 64 | GTEST_SKIP() << "Double not supported on this device"; |
| 65 | if (noHalfTests(params.lo_type_)) |
| 66 | GTEST_SKIP() << "Half not supported on this device"; |
| 67 | |
| 68 | in_ = randu(params.size_, params.in_type_); |
| 69 | lo_ = randu(params.size_, params.lo_type_) / T(10); |
| 70 | hi_ = T(1) - randu(params.size_, params.hi_type_) / T(10); |
| 71 | lo_ = lo_.as(params.lo_type_); |
| 72 | hi_ = hi_.as(params.hi_type_); |
| 73 | |
| 74 | size_t num = params.size_.elements(); |
| 75 | vector<T> hgold(num), hin(num), hlo(num), hhi(num); |
| 76 | in_.as((dtype)af::dtype_traits<T>::af_type).host(&hin[0]); |
| 77 | lo_.as((dtype)af::dtype_traits<T>::af_type).host(&hlo[0]); |
| 78 | hi_.as((dtype)af::dtype_traits<T>::af_type).host(&hhi[0]); |
| 79 | |
| 80 | for (size_t i = 0; i < num; i++) { |
| 81 | if (hin[i] < hlo[i]) |
| 82 | hgold[i] = hlo[i]; |
| 83 | else if (hin[i] > hhi[i]) |
| 84 | hgold[i] = hhi[i]; |
| 85 | else |
| 86 | hgold[i] = hin[i]; |
| 87 | } |
| 88 | |
| 89 | gold_ = array(params.size_, &hgold[0]); |
| 90 | gold_ = gold_.as(params.out_type_); |
| 91 | gold_.eval(); |
| 92 | } |
| 93 | |
| 94 | af::array in_; |
| 95 | af::array lo_; |
nothing calls this directly
no test coverage detected