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

Method SetUp

test/clamp.cpp:52–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50class 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_;

Callers

nothing calls this directly

Calls 8

noDoubleTestsFunction · 0.85
noHalfTestsFunction · 0.85
randuFunction · 0.85
asMethod · 0.80
hostMethod · 0.80
arrayClass · 0.50
elementsMethod · 0.45
evalMethod · 0.45

Tested by

no test coverage detected