Skip to content

Commit e35bff3

Browse files
Merge pull request #3 from Geode-solutions/feat/rand_engine
feat(RandomEngine): implement random engine.
2 parents 51aa712 + 0d5d072 commit e35bff3

40 files changed

Lines changed: 1885 additions & 82 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
build
22
.settings
3+
bindings/python/requirements.txt

bindings/python/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ add_geode_python_wheel(
2929
DESCRIPTION
3030
"A module of the OpenGeode framework for stochastic modeling, simulation and bayesian inference"
3131
MODULES
32-
"geometry.py"
32+
"stochastic.py"
3333
LICENSE "MIT"
3434
)
3535

bindings/python/geometry.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

bindings/python/requirements.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.

bindings/python/src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
# SOFTWARE.
2020

21-
add_subdirectory(geometry)
21+
add_subdirectory(stochastic)

bindings/python/src/geometry/CMakeLists.txt renamed to bindings/python/src/stochastic/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
# SOFTWARE.
2020

2121
add_geode_python_binding(
22-
NAME "py_geometry"
22+
NAME "py_stochastic"
2323
SOURCES
24-
"geometry.cpp"
24+
# "random_engine.cpp"
25+
"stochastic.cpp"
2526
DEPENDENCIES
26-
${PROJECT_NAME}::geometry
27+
${PROJECT_NAME}::stochastic
2728
)
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/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

bindings/python/src/geometry/geometry.cpp renamed to bindings/python/src/stochastic/stochastic.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@
2323

2424
#include <pybind11/pybind11.h>
2525

26-
#include <geode/stochastic/geometry/hello_world.hpp>
26+
#include <geode/stochastic/hello_world.hpp>
27+
#include <geode/stochastic/sampling/random_engine.hpp>
2728

28-
PYBIND11_MODULE( opengeode_stochastic_py_geometry, module )
29+
PYBIND11_MODULE( opengeode_stochastic_py_stochastic, module )
2930
{
30-
module.doc() = "OpenGeode-Stochastic Python binding for geometry";
31-
pybind11::class_< geode::StochasticGeometryLibrary >(
32-
module, "StochasticGeometryLibrary" )
33-
.def( "initialize", &geode::StochasticGeometryLibrary::initialize );
31+
module.doc() = "OpenGeode-Stochastic Python binding";
32+
pybind11::class_< geode::StochasticLibrary >( module, "StochasticLibrary" )
33+
.def( "initialize", &geode::StochasticLibrary::initialize );
3434
module.def( "hello_world", &geode::hello_world );
35+
// geode::define_random_engine( module );
3536
}
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
# SOFTWARE.
2020

21-
add_geode_test(
22-
SOURCE "test-hello-world.cpp"
23-
DEPENDENCIES
24-
OpenGeode::basic
25-
${PROJECT_NAME}::geometry
26-
)
21+
import opengeode
22+
23+
from opengeode_stochastic_py_stochastic import *
24+
25+
StochasticLibrary.initialize()

bindings/python/tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
# SOFTWARE.
2020

21-
add_subdirectory(geometry)
21+
add_subdirectory(stochastic)

0 commit comments

Comments
 (0)