Skip to content

Commit ab2294f

Browse files
start python binding
1 parent 79fa433 commit ab2294f

3 files changed

Lines changed: 55 additions & 0 deletions

File tree

bindings/python/src/geometry/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
add_geode_python_binding(
2222
NAME "py_geometry"
2323
SOURCES
24+
# "random_engine.cpp"
2425
"geometry.cpp"
2526
DEPENDENCIES
2627
${PROJECT_NAME}::geometry

bindings/python/src/geometry/geometry.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <pybind11/pybind11.h>
2525

2626
#include <geode/stochastic/geometry/hello_world.hpp>
27+
#include <geode/stochastic/geometry/random_engine.hpp>
2728

2829
PYBIND11_MODULE( opengeode_stochastic_py_geometry, module )
2930
{
@@ -32,4 +33,5 @@ PYBIND11_MODULE( opengeode_stochastic_py_geometry, module )
3233
module, "StochasticGeometryLibrary" )
3334
.def( "initialize", &geode::StochasticGeometryLibrary::initialize );
3435
module.def( "hello_world", &geode::hello_world );
36+
// geode::define_random_engine( module );
3537
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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

Comments
 (0)