| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- //
- // distribution.cpp
- // shared_random_generator
- //
- // Created by Sam Jaffe on 3/25/23.
- // Copyright © 2023 Sam Jaffe. All rights reserved.
- //
- #include "random/distribution.h"
- #include <iostream>
- #include <random>
- #include <sstream>
- #include "random/device.h"
- #define INSTANTIATE_DISTRIBUTION_TEMPLATES(T) \
- template std::string to_string(Distribution<T> const &); \
- template class Uniform<T>;
- namespace engine::random {
- template <typename T> std::string to_string(Distribution<T> const & dist) {
- std::stringstream ss;
- ss << dist;
- return ss.str();
- }
- template <typename Rand>
- Uniform<Rand>::Uniform(Rand min)
- : Uniform(min, std::numeric_limits<Rand>::max()) {}
- template <typename Rand>
- Uniform<Rand>::Uniform(Rand min, Rand max) : min_(min), max_(max) {}
- template <typename Rand>
- auto Uniform<Rand>::operator()(Device & device) const -> result_type {
- if constexpr (std::is_floating_point_v<Rand>) {
- return std::uniform_real_distribution<Rand>(min_, max_)(device);
- } else {
- return std::uniform_int_distribution<Rand>(min_, max_)(device);
- }
- }
- template <typename Rand> void Uniform<Rand>::describe(std::ostream & os) const {
- constexpr char close = std::is_floating_point_v<Rand> ? ')' : ']';
- os << typeid(Rand).name() << "Uniform[" << min_ << ',' << max_ << close;
- }
- IMPLEMENT_DEVICE(INSTANTIATE_DISTRIBUTION_TEMPLATES)
- }
|