|
| 1 | +/* |
| 2 | + * Copyright (c) 2019 - 2025 Geode-solutions |
| 3 | + * |
| 4 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | + * of this software and associated documentation files (the "Software"), to deal |
| 6 | + * in the Software without restriction, including without limitation the rights |
| 7 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | + * copies of the Software, and to permit persons to whom the Software is |
| 9 | + * furnished to do so, subject to the following conditions: |
| 10 | + * |
| 11 | + * The above copyright notice and this permission notice shall be included in |
| 12 | + * all copies or substantial portions of the Software. |
| 13 | + * |
| 14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 20 | + * SOFTWARE. |
| 21 | + * |
| 22 | + */ |
| 23 | + |
| 24 | +#include <geode/stochastic/geometry/random_engine.hpp> |
| 25 | + |
| 26 | +namespace geode |
| 27 | +{ |
| 28 | + template < typename type > |
| 29 | + type python_sample_uniform( pybind11::class_< RandomEngine >& rand_engine, |
| 30 | + const std::string& suffix ) |
| 31 | + { |
| 32 | + const auto read_suffix = absl::StrCat( "sample_uniform_", suffix ); |
| 33 | + manager.def( |
| 34 | + read_suffix.c_str(), &RandomEngine::sample_uniform< type > ); |
| 35 | + } |
| 36 | + |
| 37 | + void define_random_engine( pybind11::module& module ) |
| 38 | + { |
| 39 | + pybind11::class_< RandomEngine > rand_engine( module, "RandomEngine" ); |
| 40 | + rand_engine.def( pybind11::init<>() ) |
| 41 | + .def( "set_seed", &RandomEngine::set_seed ) |
| 42 | + .def( "sample_gaussian", &RandomEngine::sample_gaussian ) |
| 43 | + .def( "sample_bernoulli", &AttributeManager::sample_bernoulli ) |
| 44 | + .def( "attribute_exists", &AttributeManager::attribute_exists ); |
| 45 | + python_sample_uniform< index_t >( rand_engine, "index_t" ); |
| 46 | + python_sample_uniform< local_index_t >( rand_engine, "local_index_t" ); |
| 47 | + python_sample_uniform< signed_index_t >( |
| 48 | + rand_engine, "signed_index_t" ); |
| 49 | + python_sample_uniform< float >( rand_engine, "float" ); |
| 50 | + python_sample_uniform< double >( rand_engine, "double" ); |
| 51 | + } |
| 52 | +} // namespace geode |
0 commit comments