Skip to content

Commit

Permalink
Split into two functions, added Rust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tmtenbrink committed Oct 14, 2021
1 parent 4998f42 commit 0e870c8
Show file tree
Hide file tree
Showing 7 changed files with 329 additions and 79 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[package]
name = "rustfrc"
version = "1.0.2"
version = "1.0.3"
edition = "2018"

[lib]
name = "rustfrc"
crate-type = ["cdylib"]

[dependencies]
numpy = "^0.14"
ndarray = { version = "^0.15", features = ["rayon"] }
ndarray-rand = "^0.14"
numpy = "~0.14"
ndarray = { version = "~0.15", features = ["rayon"] }
ndarray-rand = "~0.14"

[dependencies.pyo3]
version = "^0.14"
version = "~0.14"
features = ["extension-module"]
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@

rustfrc is a Python package with some fast Rust functions for use with FRC resolution determination for microscopy. It is in development for use during a Bachelor end project for the TU Delft in 2021-2022.

Since rustfrc contains compiled extensions and is not pure Python, it is not available for all platforms, but only for those with available compiled wheels. As of version 1.0.1, they are available for Windows (x86_64), macOS (x86_64 and universal2, which includes Apple Silicon) and Linux (x86_64). However, since Rust and Python are supported on many platforms, it is not difficult to compile for other platforms (see below).
Since rustfrc contains compiled extensions and is not pure Python, it is not available for all platforms, but only for those with available compiled wheels. They are available for Windows (x86_64), macOS (x86_64 and universal2, which includes Apple Silicon) and Linux (x86_64). However, since Rust and Python are supported on many platforms, it is not difficult to compile for other platforms (see below).

## Features

Currently, rustfrc does not have many features. The primary one is `binom_split(x: np.ndarray) -> np.ndarray` which samples _Binom ~ (n, 0.5)_ with n as the array element value.
Currently, rustfrc does not have many features. The primary one is `binom_split(x: np.ndarray) -> np.ndarray` which samples _Binom ~ (n, 0.5)_ with n as the array element value. The operation is fully parallelized and somewhere between 3-10x faster than sampling using NumPy.

## Requirements

* Python 3.7 or greater
* numpy 1.18 or greater
* NumPy 1.18 or greater

## Installation

Expand All @@ -37,7 +37,7 @@ Build a wheel file like this (if using poetry, append `poetry run` before the co
maturin build --release
```

If you want to choose which versions of Python to build for, you can append e.g. `maturin build --release -i python3.9 python3.8 python3.7`. Here `python3.7` should be an available Python command installed on your computer.
If you want to choose which versions of Python to build for, you can write e.g. `maturin build --release -i python3.9 python3.8 python3.7`. Here, for example '`python3.7`' should be an available Python command installed on your computer.

This generates `.whl` files in `\target\wheels`. Then, create a Python environment of your choosing (with `numpy ^1.18` and `python ^3.7`), drop the `.whl` file in it and run `pip install <.whl filename>`, for example: `pip install rustfrc-0.1.0-cp39-none-win_amd64.whl`. Then, use `import rustfrc` in your Python script to be able to use the Rust functions. This should be generally valid for all platforms. The only real requirement is the availability of a Rust toolchain and Python for your platform.

Expand Down
218 changes: 203 additions & 15 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 10 additions & 22 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[project]
name = "rustfrc"
version = "1.0.2"
description = "Package with some fast Rust functions for use with FRC resolution determination for microscopy. TU Delft BEP 2021-2022."
version = "1.0.3"
description = "Fast utility functions useful for Fourier Ring/Shell Correlation: binomial splitting of arrrays"
readme = "README.md"
requires-python = ">=3.7, <3.11"
requires-python = ">= 3.7"
license = {text = "Apache-2.0"}
authors = [
{email = "[email protected]"},
Expand All @@ -16,35 +16,23 @@ classifiers = [
"Topic :: Scientific/Engineering :: Image Processing"
]
dependencies = [
'numpy >= 1.18, < 2'
"numpy >= 1.18, < 2"
]
[project.urls]
repository = "https://github.com/tmtenbrink/rustfrc"

[tool.poetry]
name = "rustfrc"
version = "1.0.2"
description = "Package with some fast Rust functions for use with FRC resolution determination for microscopy. TU Delft BEP 2021-2022."
version = "1.0.3"
description = "Fast utility functions useful for Fourier Ring/Shell Correlation: binomial splitting of arrays"
authors = ["Tip ten Brink <[email protected]>"]
readme = "README.md"
classifiers = [
"Intended Audience :: Science/Research",
"Programming Language :: Python",
"Programming Language :: Rust",
"Topic :: Scientific/Engineering :: Image Processing"
]
license = "Apache-2.0"

[tool.poetry.urls]
"Source Code" = "https://github.com/tmtenbrink/rustfrc"

[tool.poetry.dependencies]
python = ">=3.7, <3.11"
numpy = ">=1.18, < 2"
python = ">= 3.7"
numpy = ">= 1.18, < 2"

[tool.poetry.dev-dependencies]
maturin = "^0.11.3"
pytest = "^6.2.5"

[build-system]
requires = ["poetry-core>=1.0.0"]
requires = ["maturin >= 0.11, < 0.12"]
build-backend ="maturin"
2 changes: 1 addition & 1 deletion rustfrc/split.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ def binom_split(a: np.ndarray) -> np.ndarray:
binomial distribution (n, p) with n = pixel value and p = 0.5. Returns a single image.
This conserves shot noise.
"""
return _internal.binom_split(a.astype(np.int32))
return _internal.binom_split_py(a.astype(np.int32))
Loading

0 comments on commit 0e870c8

Please sign in to comment.