parent
014bad4c7d
commit
3dae67a80c
@ -0,0 +1,86 @@ |
||||
[[package]] |
||||
name = "maturin" |
||||
version = "0.13.3" |
||||
description = "Build and publish crates with pyo3, rust-cpython and cffi bindings as well as rust binaries as python packages" |
||||
category = "main" |
||||
optional = false |
||||
python-versions = ">=3.7" |
||||
|
||||
[package.dependencies] |
||||
tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""} |
||||
|
||||
[package.extras] |
||||
patchelf = ["patchelf"] |
||||
zig = ["ziglang (>=0.9.0,<0.10.0)"] |
||||
|
||||
[[package]] |
||||
name = "numpy" |
||||
version = "1.23.3" |
||||
description = "NumPy is the fundamental package for array computing with Python." |
||||
category = "main" |
||||
optional = false |
||||
python-versions = ">=3.8" |
||||
|
||||
[[package]] |
||||
name = "tomli" |
||||
version = "2.0.1" |
||||
description = "A lil' TOML parser" |
||||
category = "main" |
||||
optional = false |
||||
python-versions = ">=3.7" |
||||
|
||||
[metadata] |
||||
lock-version = "1.1" |
||||
python-versions = "^3.10" |
||||
content-hash = "fe624f7ec228aeb9ae0815762e64519bc0c1d50a59344ca345eb1c3b16e05c58" |
||||
|
||||
[metadata.files] |
||||
maturin = [ |
||||
{file = "maturin-0.13.3-py3-none-linux_armv6l.whl", hash = "sha256:4d1c443776a290b26054112bac77c370ffff89ac7b2d9a04ca0536c257f51016"}, |
||||
{file = "maturin-0.13.3-py3-none-macosx_10_7_x86_64.whl", hash = "sha256:5b3f1aa0817d30c450a46f6ef14f41e21f4f974cefd395181af9dec06a8b1d16"}, |
||||
{file = "maturin-0.13.3-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", hash = "sha256:0b8c5653c31703523232c602f6e93b76c5aaaf5af66b672155d820702dc63f69"}, |
||||
{file = "maturin-0.13.3-py3-none-manylinux_2_12_i686.manylinux2010_i686.musllinux_1_1_i686.whl", hash = "sha256:85abe7eaebd19e74a781a7512138e7dfae1504dc7cf291e7ad03234795c3c7cc"}, |
||||
{file = "maturin-0.13.3-py3-none-manylinux_2_12_x86_64.manylinux2010_x86_64.musllinux_1_1_x86_64.whl", hash = "sha256:93e97cce6da48d9c8bd73d864d1ad04728ed28a5594b6b65f1322dfd1520c485"}, |
||||
{file = "maturin-0.13.3-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.musllinux_1_1_aarch64.whl", hash = "sha256:65cc3e06dd8b9b0dc9cb813f7b61e3bd5fd327a198deabc661a6afb852d4991a"}, |
||||
{file = "maturin-0.13.3-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.musllinux_1_1_armv7l.whl", hash = "sha256:d738fd84f661e181893625a609bb89c5c35f2038967aac0deff3a5602fd28058"}, |
||||
{file = "maturin-0.13.3-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.musllinux_1_1_ppc64le.whl", hash = "sha256:a0b93434668f868387ba67d6455fc887d502c3528733311c0b7fed612d72b33b"}, |
||||
{file = "maturin-0.13.3-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:04a6cb00f125a280a7f2227c3464243d8920ed83ff5523b13fa10220395c3363"}, |
||||
{file = "maturin-0.13.3-py3-none-win32.whl", hash = "sha256:2d8a3e43790a96663a10aa53c100a26f05364d76fbd52daddd980f4c2949411f"}, |
||||
{file = "maturin-0.13.3-py3-none-win_amd64.whl", hash = "sha256:06ed41bd4771674c6f8359e8ed4f261fbb23a371a1e4f833cc9af7f5e5904fc5"}, |
||||
{file = "maturin-0.13.3-py3-none-win_arm64.whl", hash = "sha256:25eb48fc6178079c1399dff7b9ccd401747ecd174c043690f2c40425723b10c5"}, |
||||
{file = "maturin-0.13.3.tar.gz", hash = "sha256:edeb8ecaa5cc6e6d2f50a32289798d7ca046c33481ac24f74805ff289af6afe4"}, |
||||
] |
||||
numpy = [ |
||||
{file = "numpy-1.23.3-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:c9f707b5bb73bf277d812ded9896f9512a43edff72712f31667d0a8c2f8e71ee"}, |
||||
{file = "numpy-1.23.3-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:ffcf105ecdd9396e05a8e58e81faaaf34d3f9875f137c7372450baa5d77c9a54"}, |
||||
{file = "numpy-1.23.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:0ea3f98a0ffce3f8f57675eb9119f3f4edb81888b6874bc1953f91e0b1d4f440"}, |
||||
{file = "numpy-1.23.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:004f0efcb2fe1c0bd6ae1fcfc69cc8b6bf2407e0f18be308612007a0762b4089"}, |
||||
{file = "numpy-1.23.3-cp310-cp310-win32.whl", hash = "sha256:98dcbc02e39b1658dc4b4508442a560fe3ca5ca0d989f0df062534e5ca3a5c1a"}, |
||||
{file = "numpy-1.23.3-cp310-cp310-win_amd64.whl", hash = "sha256:39a664e3d26ea854211867d20ebcc8023257c1800ae89773cbba9f9e97bae036"}, |
||||
{file = "numpy-1.23.3-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:1f27b5322ac4067e67c8f9378b41c746d8feac8bdd0e0ffede5324667b8a075c"}, |
||||
{file = "numpy-1.23.3-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:2ad3ec9a748a8943e6eb4358201f7e1c12ede35f510b1a2221b70af4bb64295c"}, |
||||
{file = "numpy-1.23.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:bdc9febce3e68b697d931941b263c59e0c74e8f18861f4064c1f712562903411"}, |
||||
{file = "numpy-1.23.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:301c00cf5e60e08e04d842fc47df641d4a181e651c7135c50dc2762ffe293dbd"}, |
||||
{file = "numpy-1.23.3-cp311-cp311-win32.whl", hash = "sha256:7cd1328e5bdf0dee621912f5833648e2daca72e3839ec1d6695e91089625f0b4"}, |
||||
{file = "numpy-1.23.3-cp311-cp311-win_amd64.whl", hash = "sha256:8355fc10fd33a5a70981a5b8a0de51d10af3688d7a9e4a34fcc8fa0d7467bb7f"}, |
||||
{file = "numpy-1.23.3-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:bc6e8da415f359b578b00bcfb1d08411c96e9a97f9e6c7adada554a0812a6cc6"}, |
||||
{file = "numpy-1.23.3-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:22d43376ee0acd547f3149b9ec12eec2f0ca4a6ab2f61753c5b29bb3e795ac4d"}, |
||||
{file = "numpy-1.23.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a64403f634e5ffdcd85e0b12c08f04b3080d3e840aef118721021f9b48fc1460"}, |
||||
{file = "numpy-1.23.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:efd9d3abe5774404becdb0748178b48a218f1d8c44e0375475732211ea47c67e"}, |
||||
{file = "numpy-1.23.3-cp38-cp38-win32.whl", hash = "sha256:f8c02ec3c4c4fcb718fdf89a6c6f709b14949408e8cf2a2be5bfa9c49548fd85"}, |
||||
{file = "numpy-1.23.3-cp38-cp38-win_amd64.whl", hash = "sha256:e868b0389c5ccfc092031a861d4e158ea164d8b7fdbb10e3b5689b4fc6498df6"}, |
||||
{file = "numpy-1.23.3-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:09f6b7bdffe57fc61d869a22f506049825d707b288039d30f26a0d0d8ea05164"}, |
||||
{file = "numpy-1.23.3-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:8c79d7cf86d049d0c5089231a5bcd31edb03555bd93d81a16870aa98c6cfb79d"}, |
||||
{file = "numpy-1.23.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e5d5420053bbb3dd64c30e58f9363d7a9c27444c3648e61460c1237f9ec3fa14"}, |
||||
{file = "numpy-1.23.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d5422d6a1ea9b15577a9432e26608c73a78faf0b9039437b075cf322c92e98e7"}, |
||||
{file = "numpy-1.23.3-cp39-cp39-win32.whl", hash = "sha256:c1ba66c48b19cc9c2975c0d354f24058888cdc674bebadceb3cdc9ec403fb5d1"}, |
||||
{file = "numpy-1.23.3-cp39-cp39-win_amd64.whl", hash = "sha256:78a63d2df1d947bd9d1b11d35564c2f9e4b57898aae4626638056ec1a231c40c"}, |
||||
{file = "numpy-1.23.3-pp38-pypy38_pp73-macosx_10_9_x86_64.whl", hash = "sha256:17c0e467ade9bda685d5ac7f5fa729d8d3e76b23195471adae2d6a6941bd2c18"}, |
||||
{file = "numpy-1.23.3-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:91b8d6768a75247026e951dce3b2aac79dc7e78622fc148329135ba189813584"}, |
||||
{file = "numpy-1.23.3-pp38-pypy38_pp73-win_amd64.whl", hash = "sha256:94c15ca4e52671a59219146ff584488907b1f9b3fc232622b47e2cf832e94fb8"}, |
||||
{file = "numpy-1.23.3.tar.gz", hash = "sha256:51bf49c0cd1d52be0a240aa66f3458afc4b95d8993d2d04f0d91fa60c10af6cd"}, |
||||
] |
||||
tomli = [ |
||||
{file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"}, |
||||
{file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, |
||||
] |
@ -0,0 +1,16 @@ |
||||
[tool.poetry] |
||||
name = "rectbnpy" |
||||
version = "0.1.0" |
||||
description = "" |
||||
authors = ["AlessandroBregoli <alessandroxciv@gmail.com>"] |
||||
readme = "README.md" |
||||
|
||||
[tool.poetry.dependencies] |
||||
python = "^3.10" |
||||
maturin = "^0.13.3" |
||||
numpy = "^1.23.3" |
||||
|
||||
|
||||
[build-system] |
||||
requires = ["poetry-core"] |
||||
build-backend = "poetry.core.masonry.api" |
@ -0,0 +1,69 @@ |
||||
name: CI |
||||
|
||||
on: |
||||
push: |
||||
branches: |
||||
- main |
||||
- master |
||||
pull_request: |
||||
|
||||
jobs: |
||||
linux: |
||||
runs-on: ubuntu-latest |
||||
steps: |
||||
- uses: actions/checkout@v3 |
||||
- uses: messense/maturin-action@v1 |
||||
with: |
||||
manylinux: auto |
||||
command: build |
||||
args: --release --sdist -o dist --find-interpreter |
||||
- name: Upload wheels |
||||
uses: actions/upload-artifact@v2 |
||||
with: |
||||
name: wheels |
||||
path: dist |
||||
|
||||
windows: |
||||
runs-on: windows-latest |
||||
steps: |
||||
- uses: actions/checkout@v3 |
||||
- uses: messense/maturin-action@v1 |
||||
with: |
||||
command: build |
||||
args: --release -o dist --find-interpreter |
||||
- name: Upload wheels |
||||
uses: actions/upload-artifact@v2 |
||||
with: |
||||
name: wheels |
||||
path: dist |
||||
|
||||
macos: |
||||
runs-on: macos-latest |
||||
steps: |
||||
- uses: actions/checkout@v3 |
||||
- uses: messense/maturin-action@v1 |
||||
with: |
||||
command: build |
||||
args: --release -o dist --universal2 --find-interpreter |
||||
- name: Upload wheels |
||||
uses: actions/upload-artifact@v2 |
||||
with: |
||||
name: wheels |
||||
path: dist |
||||
|
||||
release: |
||||
name: Release |
||||
runs-on: ubuntu-latest |
||||
if: "startsWith(github.ref, 'refs/tags/')" |
||||
needs: [ macos, windows, linux ] |
||||
steps: |
||||
- uses: actions/download-artifact@v2 |
||||
with: |
||||
name: wheels |
||||
- name: Publish to PyPI |
||||
uses: messense/maturin-action@v1 |
||||
env: |
||||
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }} |
||||
with: |
||||
command: upload |
||||
args: --skip-existing * |
@ -0,0 +1,72 @@ |
||||
/target |
||||
|
||||
# Byte-compiled / optimized / DLL files |
||||
__pycache__/ |
||||
.pytest_cache/ |
||||
*.py[cod] |
||||
|
||||
# C extensions |
||||
*.so |
||||
|
||||
# Distribution / packaging |
||||
.Python |
||||
.venv/ |
||||
env/ |
||||
bin/ |
||||
build/ |
||||
develop-eggs/ |
||||
dist/ |
||||
eggs/ |
||||
lib/ |
||||
lib64/ |
||||
parts/ |
||||
sdist/ |
||||
var/ |
||||
include/ |
||||
man/ |
||||
venv/ |
||||
*.egg-info/ |
||||
.installed.cfg |
||||
*.egg |
||||
|
||||
# Installer logs |
||||
pip-log.txt |
||||
pip-delete-this-directory.txt |
||||
pip-selfcheck.json |
||||
|
||||
# Unit test / coverage reports |
||||
htmlcov/ |
||||
.tox/ |
||||
.coverage |
||||
.cache |
||||
nosetests.xml |
||||
coverage.xml |
||||
|
||||
# Translations |
||||
*.mo |
||||
|
||||
# Mr Developer |
||||
.mr.developer.cfg |
||||
.project |
||||
.pydevproject |
||||
|
||||
# Rope |
||||
.ropeproject |
||||
|
||||
# Django stuff: |
||||
*.log |
||||
*.pot |
||||
|
||||
.DS_Store |
||||
|
||||
# Sphinx documentation |
||||
docs/_build/ |
||||
|
||||
# PyCharm |
||||
.idea/ |
||||
|
||||
# VSCode |
||||
.vscode/ |
||||
|
||||
# Pyenv |
||||
.python-version |
@ -0,0 +1,15 @@ |
||||
[package] |
||||
name = "reCTBNpy" |
||||
version = "0.1.0" |
||||
edition = "2021" |
||||
|
||||
|
||||
[lib] |
||||
crate-type = ["cdylib"] |
||||
|
||||
[workspace] |
||||
|
||||
[dependencies] |
||||
pyo3 = { version = "0.17.1", features = ["extension-module"] } |
||||
numpy = "*" |
||||
reCTBN = { path="../reCTBN" } |
@ -0,0 +1,14 @@ |
||||
[build-system] |
||||
requires = ["maturin>=0.13,<0.14"] |
||||
build-backend = "maturin" |
||||
|
||||
[project] |
||||
name = "reCTBNpy" |
||||
requires-python = ">=3.7" |
||||
classifiers = [ |
||||
"Programming Language :: Rust", |
||||
"Programming Language :: Python :: Implementation :: CPython", |
||||
"Programming Language :: Python :: Implementation :: PyPy", |
||||
] |
||||
|
||||
|
@ -0,0 +1,18 @@ |
||||
use pyo3::prelude::*; |
||||
pub mod pyctbn; |
||||
pub mod pyparams; |
||||
|
||||
|
||||
|
||||
/// A Python module implemented in Rust.
|
||||
#[pymodule] |
||||
fn reCTBNpy(py: Python, m: &PyModule) -> PyResult<()> { |
||||
let network_module = PyModule::new(py, "network")?; |
||||
network_module.add_class::<pyctbn::PyCtbnNetwork>()?; |
||||
m.add_submodule(network_module)?; |
||||
|
||||
let params_module = PyModule::new(py, "params")?; |
||||
params_module.add_class::<pyparams::PyDiscreteStateContinousTime>()?; |
||||
m.add_submodule(params_module)?; |
||||
Ok(()) |
||||
} |
@ -0,0 +1,35 @@ |
||||
use std::collections::BTreeSet; |
||||
|
||||
use pyo3::prelude::*; |
||||
use reCTBN::{ctbn, network::Network}; |
||||
|
||||
#[pyclass] |
||||
pub struct PyCtbnNetwork { |
||||
ctbn_network: ctbn::CtbnNetwork, |
||||
} |
||||
|
||||
#[pymethods] |
||||
impl PyCtbnNetwork { |
||||
#[new] |
||||
pub fn new() -> Self { |
||||
PyCtbnNetwork { |
||||
ctbn_network: ctbn::CtbnNetwork::new(), |
||||
} |
||||
} |
||||
|
||||
pub fn get_number_of_nodes(&self) -> usize { |
||||
self.ctbn_network.get_number_of_nodes() |
||||
} |
||||
|
||||
pub fn add_edge(&mut self, parent: usize, child: usize) { |
||||
self.ctbn_network.add_edge(parent, child); |
||||
} |
||||
|
||||
pub fn get_parent_set(&self, node: usize) -> BTreeSet<usize> { |
||||
self.ctbn_network.get_parent_set(node) |
||||
} |
||||
|
||||
pub fn get_children_set(&self, node: usize) -> BTreeSet<usize> { |
||||
self.ctbn_network.get_children_set(node) |
||||
} |
||||
} |
@ -0,0 +1,49 @@ |
||||
use numpy::{self, ToPyArray}; |
||||
use pyo3::{exceptions::PyValueError, prelude::*}; |
||||
use reCTBN::params::{self, ParamsTrait}; |
||||
use std::collections::BTreeSet; |
||||
|
||||
pub struct PyParamsError(params::ParamsError); |
||||
|
||||
impl From<PyParamsError> for PyErr { |
||||
fn from(error: PyParamsError) -> Self { |
||||
PyValueError::new_err(error.0.to_string()) |
||||
} |
||||
} |
||||
|
||||
impl From<params::ParamsError> for PyParamsError { |
||||
fn from(other: params::ParamsError) -> Self { |
||||
Self(other) |
||||
} |
||||
} |
||||
|
||||
#[pyclass] |
||||
pub struct PyDiscreteStateContinousTime { |
||||
param: params::DiscreteStatesContinousTimeParams, |
||||
} |
||||
|
||||
#[pymethods] |
||||
impl PyDiscreteStateContinousTime { |
||||
#[new] |
||||
pub fn new(label: String, domain: BTreeSet<String>) -> Self { |
||||
PyDiscreteStateContinousTime { |
||||
param: params::DiscreteStatesContinousTimeParams::new(label, domain), |
||||
} |
||||
} |
||||
|
||||
pub fn get_cim<'py>(&self, py: Python<'py>) -> Option<&'py numpy::PyArray3<f64>> { |
||||
match self.param.get_cim() { |
||||
Some(x) => Some(x.to_pyarray(py)), |
||||
None => None, |
||||
} |
||||
} |
||||
|
||||
pub fn set_cim<'py>(&mut self, py: Python<'py>, cim: numpy::PyReadonlyArray3<f64>) -> Result<(), PyParamsError> { |
||||
self.param.set_cim(cim.as_array().to_owned())?; |
||||
Ok(()) |
||||
} |
||||
|
||||
pub fn get_label(&self) -> String { |
||||
self.param.get_label().to_string() |
||||
} |
||||
} |
Loading…
Reference in new issue