Skip to content

Commit

Permalink
New file structure as recommended by pytest, python tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tmtenbrink committed Oct 14, 2021
1 parent 0e870c8 commit d1ac77d
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 63 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/target
Cargo.lock
/.idea
/rustfrc/__pycache__
/rustfrc/*.so
/python/rustfrc/__pycache__
/rustfrc/*.so
/tests/.pytest_cache
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ ndarray-rand = "~0.14"
[dependencies.pyo3]
version = "~0.14"
features = ["extension-module"]

[package.metadata.maturin]
python-source = "python"
90 changes: 44 additions & 46 deletions poetry.lock

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

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "rustfrc"
version = "1.0.3"
description = "Fast utility functions useful for Fourier Ring/Shell Correlation: binomial splitting of arrrays"
description = "Fast utility functions useful for Fourier Ring/Shell Correlation: binomial splitting of arrays."
readme = "README.md"
requires-python = ">= 3.7"
license = {text = "Apache-2.0"}
Expand All @@ -22,7 +22,7 @@ dependencies = [
[tool.poetry]
name = "rustfrc"
version = "1.0.3"
description = "Fast utility functions useful for Fourier Ring/Shell Correlation: binomial splitting of arrays"
description = "Fast utility functions useful for Fourier Ring/Shell Correlation: binomial splitting of arrays."
authors = ["Tip ten Brink <[email protected]>"]

[tool.poetry.dependencies]
Expand Down
Empty file added python/__init__.py
Empty file.
Binary file added python/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
File renamed without changes.
Binary file not shown.
File renamed without changes.
26 changes: 13 additions & 13 deletions test.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import rustfrc as r
from python import rustfrc as r
import numpy as np
import time

init_x = (np.ones((900, 700, 100))*30).astype(np.int32)
init_x = (np.ones((900, 700, 100))*24.31)
init_y = (np.ones((900, 700, 100))*30).astype(np.int32)
init_z = np.ones((900, 700, 50))*30


start = time.perf_counter()
x = r.binom_split(init_x)
end = time.perf_counter()
print(str(end - start) + " s")


start2 = time.perf_counter()
rng = np.random.default_rng()
y = rng.binomial(init_y, 0.5)
end2 = time.perf_counter()
print(str(end2 - start2) + " s")
# start = time.perf_counter()
# x = r.binom_split(init_x)
# end = time.perf_counter()
# print(str(end - start) + " s")
#
#
# start2 = time.perf_counter()
# rng = np.random.default_rng()
# y = rng.binomial(init_y, 0.5)
# end2 = time.perf_counter()
# print(str(end2 - start2) + " s")
21 changes: 21 additions & 0 deletions tests/test_split.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import rustfrc
import numpy as np
import pytest


def test_binom_split_negative():
a = np.ones((5, 5, 5))*20
a[3, 2, 1] = -1

with pytest.raises(ValueError):
rustfrc.binom_split(a)


def test_binom_split_ok():
max_val = 15

a = np.ones((3, 7))*max_val
split_a = rustfrc.binom_split(a)

assert np.amax(split_a) <= max_val
assert np.amin(split_a) >= 0

0 comments on commit d1ac77d

Please sign in to comment.