-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 336c150
Showing
7 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/target | ||
Cargo.lock |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
name = "rustfrc" | ||
version = "0.1.0" | ||
edition = "2018" | ||
|
||
[lib] | ||
name = "rustfrc" | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
numpy = "0.14" | ||
ndarray = { version = "0.15", features = ["rayon"] } | ||
ndarray-rand = "0.14" | ||
rand = "0.8" | ||
|
||
[dependencies.pyo3] | ||
version = "0.14" | ||
features = ["extension-module"] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[tool.poetry] | ||
name = "rustfrc" | ||
version = "0.1.0" | ||
description = "Package with some basic optimized Rust functions for use with FRC resolution determination for microscopy. TU Delft BEP 2021-2022." | ||
authors = ["Tip ten Brink <[email protected]>"] | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.7" | ||
numpy = "^1.18" | ||
|
||
[tool.poetry.dev-dependencies] | ||
maturin = "^0.11.3" | ||
diplib = "3.0.0" | ||
|
||
[build-system] | ||
requires = ["poetry-core>=1.0.0"] | ||
build-backend ="maturin" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use ndarray_rand::rand_distr::Binomial; | ||
use ndarray_rand::rand::prelude::Distribution; | ||
use ndarray_rand::rand::thread_rng; | ||
use numpy::{IntoPyArray, PyArray3, PyReadonlyArray3, PyReadonlyArray2, PyArray2}; | ||
use pyo3::prelude::{pymodule, PyModule, PyResult, Python}; | ||
|
||
#[pymodule] | ||
fn rustfrc(_py: Python<'_>, m: &PyModule) -> PyResult<()> { | ||
#[pyfn(m)] | ||
fn binom_split_3d<'py>(py: Python<'py>, x: PyReadonlyArray3<'py, i32>) -> PyResult<&'py PyArray3<i32>> { | ||
let mut x = x.as_array().to_owned(); | ||
x.par_mapv_inplace(|i| { | ||
let mut rng = thread_rng(); | ||
Binomial::new(i as u64, 0.5).unwrap().sample(&mut rng) as i32 | ||
}); | ||
Ok(x.into_pyarray(py)) | ||
} | ||
|
||
#[pyfn(m)] | ||
fn binom_split_2d<'py>(py: Python<'py>, x: PyReadonlyArray2<'py, i32>) -> PyResult<&'py PyArray2<i32>> { | ||
let mut x = x.as_array().to_owned(); | ||
x.par_mapv_inplace(|i| { | ||
let mut rng = thread_rng(); | ||
Binomial::new(i as u64, 0.5).unwrap().sample(&mut rng) as i32 | ||
}); | ||
Ok(x.into_pyarray(py)) | ||
} | ||
Ok(()) | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import rustfrc as r | ||
import diplib as dip | ||
import numpy as np | ||
import time | ||
|
||
rng = np.random.default_rng() | ||
img = dip.ImageRead('Benton')(0)[:388, :388] | ||
x = np.array(img) | ||
#x3d = np.repeat(x[:, :, np.newaxis], 1000, axis=2) | ||
half_x = np.rint(x/2).astype(int) | ||
# half_x = np.rint(x/2).astype(int) | ||
# print(half_x) | ||
start = time.time_ns() | ||
#a = rng.binomial(half_x, 0.5) | ||
a = r.binom_split_2d(half_x) | ||
b = half_x - a | ||
# for i in range(100): | ||
# a = rng.binomial(half_x, 0.5) | ||
# b = half_x - a | ||
end_time = time.time_ns() | ||
print(str(float(end_time - start)/1e9) + " s") | ||
|
||
# | ||
|