Skip to content

Test on CI #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,33 @@ env:

jobs:
build:

runs-on: ubuntu-latest

name: Build and test
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [
ubuntu-latest,
windows-latest,
# macos-latest # disabled due to incompatibility. See issue #1
]
rust: [stable]
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
check-latest: true
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- name: Run tests on Release
run: cargo test --release --verbose
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ edition = "2024"

[dev-dependencies]
proptest = "1.6.0"
pyo3 = "0.23.4"
pyo3 = { version = "0.24", features = ["abi3"] }
31 changes: 14 additions & 17 deletions src/gamma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,9 @@ mod tests {
let Some((py_gamma, rs_gamma)) = unwrap(py, r, rs_gamma) else {
return;
};
let py_gamma_repr = unsafe { std::mem::transmute::<f64, i64>(py_gamma) };
let rs_gamma_repr = unsafe { std::mem::transmute::<f64, i64>(rs_gamma) };
// assert_eq!(py_gamma_repr, rs_gamma_repr, "x = {x}, py_gamma = {py_gamma}, rs_gamma = {rs_gamma}");
// allow 1 bit error for now
assert!((py_gamma_repr - rs_gamma_repr).abs() <= 1, "x = {x} diff: {}, py_gamma = {py_gamma} ({py_gamma_repr:x}), rs_gamma = {rs_gamma} ({rs_gamma_repr:x})", py_gamma_repr ^ rs_gamma_repr);
let py_gamma_repr = py_gamma.to_bits();
let rs_gamma_repr = rs_gamma.to_bits();
assert_eq!(py_gamma_repr, rs_gamma_repr, "x = {x}, py_gamma = {py_gamma}, rs_gamma = {rs_gamma}");
});
}

Expand All @@ -312,18 +310,17 @@ mod tests {

pyo3::prepare_freethreaded_python();
Python::with_gil(|py| {
let math = PyModule::import(py, "math").unwrap();
let py_lgamma_func = math
.getattr("lgamma")
.unwrap();
let r = py_lgamma_func.call1((x,));
let Some((py_lgamma, rs_lgamma)) = unwrap(py, r, rs_lgamma) else {
return;
};
let py_lgamma_repr = unsafe { std::mem::transmute::<f64, i64>(py_lgamma) };
let rs_lgamma_repr = unsafe { std::mem::transmute::<f64, i64>(rs_lgamma) };
// allow 6 bit error for now
assert!((py_lgamma_repr - rs_lgamma_repr).abs() <= 6, "x = {x} diff: {}, py_lgamma = {py_lgamma} ({py_lgamma_repr:x}), rs_lgamma = {rs_lgamma} ({rs_lgamma_repr:x})", py_lgamma_repr ^ rs_lgamma_repr);
let math = PyModule::import(py, "math").unwrap();
let py_lgamma_func = math
.getattr("lgamma")
.unwrap();
let r = py_lgamma_func.call1((x,));
let Some((py_lgamma, rs_lgamma)) = unwrap(py, r, rs_lgamma) else {
return;
};
let py_lgamma_repr = py_lgamma.to_bits();
let rs_lgamma_repr = rs_lgamma.to_bits();
assert_eq!(py_lgamma_repr, rs_lgamma_repr, "x = {x}, py_lgamma = {py_lgamma}, rs_gamma = {rs_lgamma}");
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ mod err;
mod gamma;

pub use err::Error;
pub use gamma::{tgamma as gamma, lgamma};
pub use gamma::{lgamma, tgamma as gamma};
Loading