#ifndef CAFFE2_CORE_DISTRIBUTIONS_STUBS_H_ #define CAFFE2_CORE_DISTRIBUTIONS_STUBS_H_ #include /** * This file provides distributions compatible with * ATen/core/DistributionsHelper.h but backed with the std RNG implementation * instead of the ATen one. * * Caffe2 mobile builds currently do not depend on all of ATen so this is * required to allow using the faster ATen RNG for normal builds but keep the * build size small on mobile. RNG performance typically doesn't matter on * mobile builds since the models are small and rarely using random * initialization. */ namespace at { namespace { template struct distribution_adapter { template C10_HOST_DEVICE inline distribution_adapter(Args... args) : distribution_(std::forward(args)...) {} template C10_HOST_DEVICE inline R operator()(RNG generator) { return distribution_(*generator); } private: T distribution_; }; template struct uniform_int_from_to_distribution : distribution_adapter> { C10_HOST_DEVICE inline uniform_int_from_to_distribution( uint64_t range, int64_t base) : distribution_adapter>( base, // std is inclusive, at is exclusive base + range - 1) {} }; template using uniform_real_distribution = distribution_adapter>; template using normal_distribution = distribution_adapter>; template using bernoulli_distribution = distribution_adapter; template using exponential_distribution = distribution_adapter>; template using cauchy_distribution = distribution_adapter>; template using lognormal_distribution = distribution_adapter>; } // namespace } // namespace at #endif // CAFFE2_CORE_DISTRIBUTIONS_STUBS_H_