@@ -166,6 +166,29 @@ bool compare_moments(const std::vector<Fp, AllocType>& r, double tM, double tD,
166166 return true ;
167167}
168168
169+ template <typename Distribution, typename Fp, typename AllocType>
170+ bool calculate_and_compare_moments_uniform (Distribution distr,
171+ const std::vector<Fp, AllocType>& r) {
172+ double tM, tD, tQ;
173+ double a = distr.a ();
174+ double b = distr.b ();
175+
176+ // Theoretical moments
177+ if constexpr (std::is_integral<Fp>::value) {
178+ tM = (a + b - 1.0 ) / 2.0 ;
179+ tD = ((b - a) * (b - a) - 1.0 ) / 12.0 ;
180+ tQ = (((b - a) * (b - a)) * ((1.0 / 80.0 ) * (b - a) * (b - a) - (1.0 / 24.0 ))) +
181+ (7.0 / 240.0 );
182+ }
183+ else {
184+ tM = (b + a) / 2.0 ;
185+ tD = ((b - a) * (b - a)) / 12.0 ;
186+ tQ = ((b - a) * (b - a) * (b - a) * (b - a)) / 80.0 ;
187+ }
188+
189+ return compare_moments (r, tM, tD, tQ);
190+ }
191+
169192template <typename Distribution>
170193struct statistics_device {};
171194
@@ -174,92 +197,79 @@ struct statistics_device<oneapi::math::rng::device::uniform<Fp, Method>> {
174197 template <typename AllocType>
175198 bool check (const std::vector<Fp, AllocType>& r,
176199 const oneapi::math::rng::device::uniform<Fp, Method>& distr) {
177- double tM, tD, tQ ;
178- Fp a = distr. a ();
179- Fp b = distr. b () ;
200+ return calculate_and_compare_moments_uniform (distr, r) ;
201+ }
202+ } ;
180203
181- // Theoretical moments
182- tM = (b + a) / 2.0 ;
183- tD = ((b - a) * (b - a)) / 12.0 ;
184- tQ = ((b - a) * (b - a) * (b - a) * (b - a)) / 80.0 ;
204+ template <typename Method>
205+ struct statistics_device <oneapi::math::rng::device::uniform<std::int8_t , Method>> {
206+ template <typename AllocType>
207+ bool check (const std::vector<std::int8_t , AllocType>& r,
208+ const oneapi::math::rng::device::uniform<std::int8_t , Method>& distr) {
209+ return calculate_and_compare_moments_uniform (distr, r);
210+ }
211+ };
185212
186- return compare_moments (r, tM, tD, tQ);
213+ template <typename Method>
214+ struct statistics_device <oneapi::math::rng::device::uniform<std::uint8_t , Method>> {
215+ template <typename AllocType>
216+ bool check (const std::vector<std::uint8_t , AllocType>& r,
217+ const oneapi::math::rng::device::uniform<std::uint8_t , Method>& distr) {
218+ return calculate_and_compare_moments_uniform (distr, r);
187219 }
188220};
189221
190222template <typename Method>
191- struct statistics_device <oneapi::math::rng::device::uniform<std::int32_t , Method>> {
223+ struct statistics_device <oneapi::math::rng::device::uniform<std::int16_t , Method>> {
192224 template <typename AllocType>
193- bool check (const std::vector<std::int32_t , AllocType>& r,
194- const oneapi::math::rng::device::uniform<std::int32_t , Method>& distr) {
195- double tM, tD, tQ ;
196- double a = distr. a ();
197- double b = distr. b () ;
225+ bool check (const std::vector<std::int16_t , AllocType>& r,
226+ const oneapi::math::rng::device::uniform<std::int16_t , Method>& distr) {
227+ return calculate_and_compare_moments_uniform (distr, r) ;
228+ }
229+ } ;
198230
199- // Theoretical moments
200- tM = (a + b - 1.0 ) / 2.0 ;
201- tD = ((b - a) * (b - a) - 1.0 ) / 12.0 ;
202- tQ = (((b - a) * (b - a)) * ((1.0 / 80.0 ) * (b - a) * (b - a) - (1.0 / 24.0 ))) +
203- (7.0 / 240.0 );
231+ template <typename Method>
232+ struct statistics_device <oneapi::math::rng::device::uniform<std::uint16_t , Method>> {
233+ template <typename AllocType>
234+ bool check (const std::vector<std::uint16_t , AllocType>& r,
235+ const oneapi::math::rng::device::uniform<std::uint16_t , Method>& distr) {
236+ return calculate_and_compare_moments_uniform (distr, r);
237+ }
238+ };
204239
205- return compare_moments (r, tM, tD, tQ);
240+ template <typename Method>
241+ struct statistics_device <oneapi::math::rng::device::uniform<std::int32_t , Method>> {
242+ template <typename AllocType>
243+ bool check (const std::vector<int32_t , AllocType>& r,
244+ const oneapi::math::rng::device::uniform<int32_t , Method>& distr) {
245+ return calculate_and_compare_moments_uniform (distr, r);
206246 }
207247};
208248
209249template <typename Method>
210250struct statistics_device <oneapi::math::rng::device::uniform<std::uint32_t , Method>> {
211251 template <typename AllocType>
212- bool check (const std::vector<std::uint32_t , AllocType>& r,
213- const oneapi::math::rng::device::uniform<std::uint32_t , Method>& distr) {
214- double tM, tD, tQ;
215- double a = distr.a ();
216- double b = distr.b ();
217-
218- // Theoretical moments
219- tM = (a + b - 1.0 ) / 2.0 ;
220- tD = ((b - a) * (b - a) - 1.0 ) / 12.0 ;
221- tQ = (((b - a) * (b - a)) * ((1.0 / 80.0 ) * (b - a) * (b - a) - (1.0 / 24.0 ))) +
222- (7.0 / 240.0 );
223-
224- return compare_moments (r, tM, tD, tQ);
252+ bool check (const std::vector<uint32_t , AllocType>& r,
253+ const oneapi::math::rng::device::uniform<uint32_t , Method>& distr) {
254+ return calculate_and_compare_moments_uniform (distr, r);
225255 }
226256};
227257
228258template <typename Method>
229259struct statistics_device <oneapi::math::rng::device::uniform<std::int64_t , Method>> {
230260 template <typename AllocType>
231- bool check (const std::vector<std::int64_t , AllocType>& r,
232- const oneapi::math::rng::device::uniform<std::int64_t , Method>& distr) {
233- double tM, tD, tQ;
234- double a = distr.a ();
235- double b = distr.b ();
236-
237- // Theoretical moments
238- tM = (a + b - 1.0 ) / 2.0 ;
239- tD = ((b - a) * (b - a) - 1.0 ) / 12.0 ;
240- tQ = (((b - a) * (b - a)) * ((1.0 / 80.0 ) * (b - a) * (b - a) - (1.0 / 24.0 ))) +
241- (7.0 / 240.0 );
242-
243- return compare_moments (r, tM, tD, tQ);
261+ bool check (const std::vector<int64_t , AllocType>& r,
262+ const oneapi::math::rng::device::uniform<int64_t , Method>& distr) {
263+ return calculate_and_compare_moments_uniform (distr, r);
244264 }
245265};
246266
247267template <typename Method>
248268struct statistics_device <oneapi::math::rng::device::uniform<std::uint64_t , Method>> {
249269 template <typename AllocType>
250- bool check (const std::vector<std::uint64_t , AllocType>& r,
251- const oneapi::math::rng::device::uniform<std::uint64_t , Method>& distr) {
252- double tM, tD, tQ;
253- double a = distr.a ();
254- double b = distr.b ();
255-
256- // Theoretical moments
257- tM = (a + b - 1.0 ) / 2.0 ;
258- tD = ((b - a) * (b - a) - 1.0 ) / 12.0 ;
259- tQ = (((b - a) * (b - a)) * ((1.0 / 80.0 ) * (b - a) * (b - a) - (1.0 / 24.0 ))) +
260- (7.0 / 240.0 );
261-
262- return compare_moments (r, tM, tD, tQ);
270+ bool check (const std::vector<uint64_t , AllocType>& r,
271+ const oneapi::math::rng::device::uniform<uint64_t , Method>& distr) {
272+ return calculate_and_compare_moments_uniform (distr, r);
263273 }
264274};
265275
0 commit comments