24 #include "cheetah/data/test_utils/FrequencySeriesTester.h" 25 #include "cheetah/data/FrequencySeries.h" 26 #include <panda/TypeTraits.h> 35 template<
class Alloc,
typename DeviceType,
typename Enable>
36 struct ConstructAllocatorHelper;
38 template<
class Alloc,
typename DeviceType>
39 struct ConstructAllocatorHelper<Alloc, DeviceType,
std::true_type>
42 Alloc construct(DeviceType& device)
48 template<
class Alloc,
typename DeviceType>
49 struct ConstructAllocatorHelper<Alloc, DeviceType,
std::false_type> {
51 Alloc construct(DeviceType&)
56 template<
class Alloc,
typename DeviceType>
57 struct ConstructAllocator
61 using HasDeviceConstructorT = decltype(T(std::declval<DeviceType&>()));
65 Alloc construct(DeviceType& device)
67 return ConstructAllocatorHelper<Alloc, DeviceType, typename std::conditional<panda::HasMethod<Alloc,HasDeviceConstructorT>::value, std::true_type, std::false_type>::type>::construct(device);
72 template<
typename FrequencySeriesT>
73 typename FrequencySeriesTesterTraits<FrequencySeriesT>::Allocator FrequencySeriesTesterTraits<FrequencySeriesT>::allocator(panda::PoolResource<Arch>& device)
75 return ConstructAllocator<Allocator, panda::PoolResource<Arch>>::construct(device);
78 template<
typename FrequencySeriesTesterTraitsT>
79 FrequencySeriesTester<FrequencySeriesTesterTraitsT>::FrequencySeriesTester()
83 TYPED_TEST_P(FrequencySeriesTester, construct_resize)
85 typedef TypeParam Traits;
86 typedef typename Traits::FrequencySeriesType FrequencySeriesType;
89 for(
auto& device : this->_system.devices()) {
90 FrequencySeriesType series(traits.allocator(*device));
91 ASSERT_EQ(series.size(), std::size_t(0));
94 ASSERT_EQ(series.size(), std::size_t(2));
97 ASSERT_EQ(series.size(), std::size_t(1));
99 auto it = series.begin();
101 ASSERT_EQ(series.size(), std::size_t(1));
102 ASSERT_EQ(it, series.begin());
106 TYPED_TEST_P(FrequencySeriesTester, begin_end)
108 typedef TypeParam Traits;
109 typedef typename Traits::FrequencySeriesType FrequencySeriesType;
113 for(
auto& device : this->_system.devices()) {
114 FrequencySeriesType series(n, traits.allocator(*device));
119 auto it = series.begin();
120 ASSERT_EQ(n, std::size_t(std::distance(it, series.end())));
121 while(it != series.end()) {
129 const FrequencySeriesType& const_series = series;
132 auto it = const_series.begin();
133 ASSERT_EQ(n, std::size_t(std::distance(it, const_series.end())));
134 while(it != const_series.end()) {
144 auto it = const_series.cbegin();
145 ASSERT_EQ(n, std::size_t(std::distance(it, series.cend())));
146 while(it != const_series.cend()) {
155 TYPED_TEST_P(FrequencySeriesTester, host_conversion)
157 typedef TypeParam Traits;
158 typedef typename Traits::FrequencySeriesType FrequencySeriesType;
159 typedef typename FrequencySeriesType::ValueType ValueType;
160 typedef FrequencySeries<panda::Cpu, ValueType, std::allocator<ValueType>> HostFrequencySeriesType;
161 FourierFrequencyType df = 5.4 * hz;
165 HostFrequencySeriesType host_data(df, n, std::allocator<ValueType>());
167 std::transform(host_data.begin(), host_data.end(), host_data.begin(), [&](ValueType
const&) {
return ++value; });
170 for(
auto& device : this->_system.devices()) {
172 auto allocator = traits.allocator(*device);
173 FrequencySeriesType series(host_data, allocator);
174 ASSERT_EQ(series.size(), host_data.size());
176 HostFrequencySeriesType host_data_copy(series);
177 ASSERT_EQ(host_data_copy.size(), n);
178 auto copy_it=host_data_copy.cbegin();
179 auto it=host_data.cbegin();
181 while(it!=host_data.cend()) {
182 SCOPED_TRACE(
"element number: " + std::to_string(count));
183 ASSERT_EQ(*it, *copy_it) << host_data[count];
188 ASSERT_EQ(df,host_data.frequency_step());
192 REGISTER_TYPED_TEST_CASE_P(FrequencySeriesTester, construct_resize, begin_end, host_conversion);
Some limits and constants for FLDO.