Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
DmTrialsTester.cpp
1 /*
2  * The MIT License (MIT)
3  *
4  * Copyright (c) 2016 The SKA organisation
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #include "cheetah/data/test_utils/DmTrialsTester.h"
25 #include "cheetah/data/DmTrials.h"
26 #include <cmath>
27 #include <numeric>
28 
29 
30 namespace ska {
31 namespace cheetah {
32 namespace data {
33 namespace test {
34 
35 
36 template<typename DmTrialsTesterTraitsT>
37 DmTrialsTester<DmTrialsTesterTraitsT>::DmTrialsTester()
38 {
39 }
40 
41 TYPED_TEST_P(DmTrialsTester, construct_nullptr_metadata)
42 {
43  typedef TypeParam Traits;
44  typedef typename Traits::DmTrialsType DmTrialsType;
45  typedef typename DmTrialsType::TimeType TimeType;
46  typedef typename DmTrialsType::DmType Dm;
47 
48  Traits traits;
49  auto now = cheetah::utils::ModifiedJulianClock::now();
50  std::shared_ptr<data::DmTrialsMetadata> metadata;
51 
52  for(auto& device : this->_system.devices()) {
53  ASSERT_THROW(DmTrialsType dm_trials(metadata, now, traits.allocator(*device)), panda::Error);
54  }
55 }
56 
57 TYPED_TEST_P(DmTrialsTester, construct_empty_metadata)
58 {
59  typedef TypeParam Traits;
60  typedef typename Traits::DmTrialsType DmTrialsType;
61  typedef typename DmTrialsType::TimeType TimeType;
62  typedef typename DmTrialsType::DmType Dm;
63 
64  Traits traits;
65  auto now = cheetah::utils::ModifiedJulianClock::now();
66  auto metadata = data::DmTrialsMetadata::make_shared(TimeType(0.000064*data::seconds),1<<6);
67 
68  for(auto& device : this->_system.devices()) {
69  ASSERT_THROW(DmTrialsType dm_trials(metadata, now, traits.allocator(*device)), panda::Error);
70  }
71 }
72 
73 TYPED_TEST_P(DmTrialsTester, begin_end)
74 {
75  typedef TypeParam Traits;
76  typedef typename Traits::DmTrialsType DmTrialsType;
77  typedef typename DmTrialsType::DmType Dm;
78 
79  Traits traits;
80  auto now = cheetah::utils::ModifiedJulianClock::now();
81  std::size_t size=1<<6;
82  auto metadata = data::DmTrialsMetadata::make_shared(TimeType(0.000064*data::seconds), size);
83  metadata->emplace_back(Dm(0.0*data::parsecs_per_cube_cm),1);
84  metadata->emplace_back(Dm(10.0*data::parsecs_per_cube_cm),2);
85  metadata->emplace_back(Dm(20.0*data::parsecs_per_cube_cm),4);
86 
87  std::size_t n=metadata->size();
88  for(auto& device : this->_system.devices()) {
89  DmTrialsType dm_trials(metadata, now, traits.allocator(*device));
90 
91  // begin end on non-const object
92  std::size_t count=0;
93  {
94  auto it = dm_trials.begin();
95  ASSERT_EQ(n, std::size_t(std::distance(it, dm_trials.end())));
96  while(it != dm_trials.end()) {
97  ++count;
98  ++it;
99  }
100  ASSERT_EQ(count, n);
101  }
102 
103  // begin end on const object
104  const DmTrialsType& const_dm_trials = dm_trials;
105  {
106  count=0;
107  auto it = const_dm_trials.begin();
108  ASSERT_EQ(n, std::size_t(std::distance(it, const_dm_trials.end())));
109  while(it != const_dm_trials.end()) {
110  ++count;
111  ++it;
112  }
113  ASSERT_EQ(count, n);
114  }
115 
116  // cbegin cend on const object
117  {
118  count=0;
119  auto it = const_dm_trials.cbegin();
120  ASSERT_EQ(n, std::size_t(std::distance(it, dm_trials.cend())));
121  while(it != const_dm_trials.cend()) {
122  ASSERT_EQ(it->size(), std::size_t((size)/std::pow(2, count)) ) << count;
123  ++it;
124  ++count;
125  }
126  ASSERT_EQ(count, n);
127  }
128  }
129 }
130 
131 TYPED_TEST_P(DmTrialsTester, host_conversion)
132 {
133  typedef TypeParam Traits;
134  typedef typename Traits::DmTrialsType DmTrialsType;
135  typedef typename DmTrialsType::DmType Dm;
136  typedef typename DmTrialsType::ValueType ValueType;
137 
138  auto now = cheetah::utils::ModifiedJulianClock::now();
139  std::size_t size=1<<4;
140  auto metadata = data::DmTrialsMetadata::make_shared(TimeType(0.000064*data::seconds), size);
141  metadata->emplace_back(Dm(0.0*data::parsecs_per_cube_cm),1);
142  metadata->emplace_back(Dm(10.0*data::parsecs_per_cube_cm),2);
143  metadata->emplace_back(Dm(20.0*data::parsecs_per_cube_cm),4);
144 
145  typedef typename DmTrialsType::ValueType ValueType;
146  typedef DmTrials<panda::Cpu, ValueType, std::allocator<ValueType>> HostDmTrialsType;
147 
148  // some host based data
149  HostDmTrialsType host_data(metadata, now, std::allocator<ValueType>());
150  for(auto& trial : host_data) {
151  std::iota(trial.begin(), trial.end(), 1);
152  }
153 
154  Traits traits;
155  for(auto& device : this->_system.devices()) {
156  // copy host data to target DmTrials
157  DmTrialsType dm_trials(host_data, traits.allocator(*device));
158  ASSERT_EQ(dm_trials.size(), host_data.size());
159  // copy back from target to host
160  HostDmTrialsType host_data_copy(dm_trials);
161  ASSERT_EQ(host_data_copy.size(), metadata->size());
162  auto copy_it=host_data_copy.cbegin();
163  auto it=host_data.cbegin();
164  while(it!=host_data.cend()) {
165  ASSERT_EQ(it->size(), copy_it->size());
166  auto copy_trial_it=copy_it->begin();
167  for(auto const& v : *it) {
168  ASSERT_EQ(v, *copy_trial_it);
169  ++copy_trial_it;
170  }
171  ++it;
172  ++copy_it;
173  }
174  }
175 }
176 
177 REGISTER_TYPED_TEST_CASE_P(DmTrialsTester, construct_nullptr_metadata, construct_empty_metadata, begin_end, host_conversion);
178 
179 } // namespace test
180 } // namespace data
181 } // namespace cheetah
182 } // namespace ska
Some limits and constants for FLDO.
Definition: Brdz.h:35