Skip to content

Commit

Permalink
support 3.13t free-threaded python (#471)
Browse files Browse the repository at this point in the history
* support 3.13t free-threaded python

* make dynamic borrow-checking threadsafe

* fix compiler error in benches target

* fix warning on nightly rust about extern usage

* remove parking_lot dependency

* Add deadlock-avoidance using direct FFI calls

* refactor BorrowFlags tests to not hold a lock in the tests

* fix clippy

* give BorrowFlagsState fields descriptive names

* move thread state guard into the crate root

* use ThreadStateGuard to avoid deadlocks acquiring the dtype cache

---------

Co-authored-by: Icxolu <10486322+Icxolu@users.noreply.github.com>
Co-authored-by: Nathan Goldbaum <nathan.goldbaum@gmail.com>
  • Loading branch information
3 people authored Feb 19, 2025
1 parent 2a579ad commit 8dd4f8e
Show file tree
Hide file tree
Showing 10 changed files with 198 additions and 144 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
"3.11",
"3.12",
"3.13",
"3.13t",
"pypy-3.9",
"pypy-3.10",
]
Expand Down Expand Up @@ -108,7 +109,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
uses: Quansight-Labs/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
architecture: ${{ matrix.platform.python-architecture }}
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Changelog
- v0.24.0
- Support Python 3.13t "free-threaded" Python. ([#471](https://github.com/PyO3/rust-numpy/pull/471)

- v0.23.0
- Drop support for PyPy 3.7 and 3.8. ([#470](https://github.com/PyO3/rust-numpy/pull/470))
- Require `Element: Sync` as part of the free-threading support in PyO3 0.23 ([#469](https://github.com/PyO3/rust-numpy/pull/469))
Expand Down
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ num-complex = ">= 0.2, < 0.5"
num-integer = "0.1"
num-traits = "0.2"
ndarray = ">= 0.15, < 0.17"
pyo3 = { version = "0.23.3", default-features = false, features = ["macros"] }
pyo3 = { version = "0.23.4", default-features = false, features = ["macros"] }
rustc-hash = "2.0"

[dev-dependencies]
pyo3 = { version = "0.23.3", default-features = false, features = ["auto-initialize"] }
nalgebra = { version = ">=0.30, <0.34", default-features = false, features = ["std"] }

[build-dependencies]
pyo3-build-config = { version = "0.23.1", features = ["resolve-config"] }

[package.metadata.docs.rs]
all-features = true
8 changes: 6 additions & 2 deletions benches/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use test::{black_box, Bencher};
use std::ops::Range;

use numpy::{PyArray1, PyArray2, PyArray3};
use pyo3::{types::PyAnyMethods, Bound, Python};
use pyo3::{types::PyAnyMethods, Bound, IntoPyObjectExt, Python};

#[bench]
fn extract_success(bencher: &mut Bencher) {
Expand Down Expand Up @@ -115,7 +115,11 @@ fn from_slice_large(bencher: &mut Bencher) {
}

fn from_object_slice(bencher: &mut Bencher, size: usize) {
let vec = Python::with_gil(|py| (0..size).map(|val| val.to_object(py)).collect::<Vec<_>>());
let vec = Python::with_gil(|py| {
(0..size)
.map(|val| val.into_py_any(py).unwrap())
.collect::<Vec<_>>()
});

Python::with_gil(|py| {
bencher.iter(|| {
Expand Down
3 changes: 3 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
pyo3_build_config::use_pyo3_cfgs();
}
Loading

0 comments on commit 8dd4f8e

Please sign in to comment.