From 919292f562b3cb9544ff03b2a535713c2bd4c63d Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Mon, 21 Apr 2025 10:35:00 +0900 Subject: [PATCH 1/2] bit test --- src/gamma.rs | 31 ++++++++++++++----------------- src/lib.rs | 2 +- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/gamma.rs b/src/gamma.rs index 4692fe1..7dd6f98 100644 --- a/src/gamma.rs +++ b/src/gamma.rs @@ -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::(py_gamma) }; - let rs_gamma_repr = unsafe { std::mem::transmute::(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}"); }); } @@ -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::(py_lgamma) }; - let rs_lgamma_repr = unsafe { std::mem::transmute::(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}"); }); } } diff --git a/src/lib.rs b/src/lib.rs index 03db84f..1a884f7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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}; From a77d62b61dbed676df5d6d2bf88330d19879421b Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Mon, 21 Apr 2025 10:38:52 +0900 Subject: [PATCH 2/2] Run CI on windows/macos --- .github/workflows/rust.yml | 27 ++++++++++++++++++++++++--- Cargo.toml | 2 +- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 9fd45e0..98ec583 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -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 diff --git a/Cargo.toml b/Cargo.toml index b80f9cb..6347416 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,4 +5,4 @@ edition = "2024" [dev-dependencies] proptest = "1.6.0" -pyo3 = "0.23.4" +pyo3 = { version = "0.24", features = ["abi3"] }