| 44 | |
| 45 | template<typename T> |
| 46 | void DimCheck(const vector<af_seq> &seqs) { |
| 47 | SUPPORTED_TYPE_CHECK(T); |
| 48 | |
| 49 | static const int ndims = 1; |
| 50 | static const size_t dims = 100; |
| 51 | |
| 52 | dim_t d[1] = {dims}; |
| 53 | |
| 54 | vector<T> hData(dims); |
| 55 | for (int i = 0; i < (int)dims; i++) { hData[i] = i; } |
| 56 | |
| 57 | af_array a = 0; |
| 58 | ASSERT_SUCCESS(af_create_array(&a, &hData.front(), ndims, d, |
| 59 | (af_dtype)dtype_traits<T>::af_type)); |
| 60 | |
| 61 | vector<af_array> indexed_array(seqs.size(), 0); |
| 62 | for (size_t i = 0; i < seqs.size(); i++) { |
| 63 | ASSERT_SUCCESS(af_index(&(indexed_array[i]), a, ndims, &seqs[i])) |
| 64 | << "where seqs[i].begin == " << seqs[i].begin |
| 65 | << " seqs[i].step == " << seqs[i].step |
| 66 | << " seqs[i].end == " << seqs[i].end; |
| 67 | } |
| 68 | |
| 69 | vector<T *> h_indexed(seqs.size()); |
| 70 | for (size_t i = 0; i < seqs.size(); i++) { |
| 71 | dim_t elems; |
| 72 | ASSERT_SUCCESS(af_get_elements(&elems, indexed_array[i])); |
| 73 | h_indexed[i] = new T[elems]; |
| 74 | ASSERT_SUCCESS( |
| 75 | af_get_data_ptr((void *)(h_indexed[i]), indexed_array[i])); |
| 76 | } |
| 77 | |
| 78 | for (size_t k = 0; k < seqs.size(); k++) { |
| 79 | if (seqs[k].step > 0) { |
| 80 | checkValues(seqs[k], &hData.front(), h_indexed[k], |
| 81 | std::less_equal<int>()); |
| 82 | } else if (seqs[k].step < 0) { |
| 83 | checkValues(seqs[k], &hData.front(), h_indexed[k], |
| 84 | std::greater_equal<int>()); |
| 85 | } else { |
| 86 | for (size_t i = 0; i <= seqs[k].end; i++) { |
| 87 | ASSERT_DOUBLE_EQ(real(hData[i]), real(h_indexed[k][i])) |
| 88 | << "Where i = " << i; |
| 89 | } |
| 90 | } |
| 91 | delete[] h_indexed[k]; |
| 92 | } |
| 93 | |
| 94 | ASSERT_SUCCESS(af_release_array(a)); |
| 95 | for (size_t i = 0; i < indexed_array.size(); i++) { |
| 96 | ASSERT_SUCCESS(af_release_array(indexed_array[i])); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | template<typename T> |
| 101 | class Indexing1D : public ::testing::Test { |
nothing calls this directly
no test coverage detected