Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- v0.26.0
- bump MSRV to 1.74, matching PyO3 ([#504](https://github.com/PyO3/rust-numpy/pull/504))
- extend supported `nalgebra` version to `0.34` ([#503](https://github.com/PyO3/rust-numpy/pull/503))
- Bump PyO3 dependency to v0.26.0. ([#506](https://github.com/PyO3/rust-numpy/pull/506))

- v0.25.0,
- Bump PyO3 dependency to v0.25.0. ([#492](https://github.com/PyO3/rust-numpy/pull/492))
Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "numpy"
version = "0.25.0"
version = "0.26.0"
authors = [
"The rust-numpy Project Developers",
"PyO3 Project and Contributors <https://github.com/PyO3>",
Expand All @@ -22,19 +22,19 @@ num-complex = ">= 0.2, < 0.5"
num-integer = "0.1"
num-traits = "0.2"
ndarray = ">= 0.15, < 0.17"
pyo3 = { version = "0.25.0", default-features = false, features = ["macros"] }
pyo3 = { version = "0.26.0", default-features = false, features = ["macros"]}
rustc-hash = "2.0"

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

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

[package.metadata.docs.rs]
all-features = true
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ use numpy::{PyArray1, PyArrayMethods};
use pyo3::{types::{IntoPyDict, PyAnyMethods}, PyResult, Python, ffi::c_str};

fn main() -> PyResult<()> {
Python::with_gil(|py| {
Python::attach(|py| {
let np = py.import("numpy")?;
let locals = [("np", np)].into_py_dict(py)?;

let pyarray = py
.eval(c_str!("np.absolute(np.array([-1, -2, -3], dtype='int32'))"), Some(&locals), None)?
.downcast_into::<PyArray1<i32>>()?;
.cast_into::<PyArray1<i32>>()?;

let readonly = pyarray.readonly();
let slice = readonly.as_slice()?;
Expand Down
28 changes: 14 additions & 14 deletions benches/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use pyo3::{types::PyAnyMethods, Bound, IntoPyObjectExt, Python};

#[bench]
fn extract_success(bencher: &mut Bencher) {
Python::with_gil(|py| {
Python::attach(|py| {
let any = PyArray2::<f64>::zeros(py, (10, 10), false).into_any();

bencher.iter(|| {
Expand All @@ -23,7 +23,7 @@ fn extract_success(bencher: &mut Bencher) {

#[bench]
fn extract_failure(bencher: &mut Bencher) {
Python::with_gil(|py| {
Python::attach(|py| {
let any = PyArray2::<f64>::zeros(py, (10, 10), false).into_any();

bencher.iter(|| {
Expand All @@ -35,20 +35,20 @@ fn extract_failure(bencher: &mut Bencher) {
}

#[bench]
fn downcast_success(bencher: &mut Bencher) {
Python::with_gil(|py| {
fn cast_success(bencher: &mut Bencher) {
Python::attach(|py| {
let any = PyArray2::<f64>::zeros(py, (10, 10), false).into_any();

bencher.iter(|| black_box(&any).downcast::<PyArray2<f64>>().unwrap());
bencher.iter(|| black_box(&any).cast::<PyArray2<f64>>().unwrap());
});
}

#[bench]
fn downcast_failure(bencher: &mut Bencher) {
Python::with_gil(|py| {
fn cast_failure(bencher: &mut Bencher) {
Python::attach(|py| {
let any = PyArray2::<f64>::zeros(py, (10, 10), false).into_any();

bencher.iter(|| black_box(&any).downcast::<PyArray2<f64>>().unwrap_err());
bencher.iter(|| black_box(&any).cast::<PyArray2<f64>>().unwrap_err());
});
}

Expand All @@ -63,7 +63,7 @@ impl Iterator for Iter {
}

fn from_iter(bencher: &mut Bencher, size: usize) {
Python::with_gil(|py| {
Python::attach(|py| {
bencher.iter(|| {
let iter = black_box(Iter(0..size));

Expand All @@ -90,7 +90,7 @@ fn from_iter_large(bencher: &mut Bencher) {
fn from_slice(bencher: &mut Bencher, size: usize) {
let vec = (0..size).collect::<Vec<_>>();

Python::with_gil(|py| {
Python::attach(|py| {
bencher.iter(|| {
let slice = black_box(&vec);

Expand All @@ -115,13 +115,13 @@ fn from_slice_large(bencher: &mut Bencher) {
}

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

Python::with_gil(|py| {
Python::attach(|py| {
bencher.iter(|| {
let slice = black_box(&vec);

Expand All @@ -148,7 +148,7 @@ fn from_object_slice_large(bencher: &mut Bencher) {
fn from_vec2(bencher: &mut Bencher, size: usize) {
let vec2 = vec![vec![0; size]; size];

Python::with_gil(|py| {
Python::attach(|py| {
bencher.iter(|| {
let vec2 = black_box(&vec2);

Expand All @@ -175,7 +175,7 @@ fn from_vec2_large(bencher: &mut Bencher) {
fn from_vec3(bencher: &mut Bencher, size: usize) {
let vec3 = vec![vec![vec![0; size]; size]; size];

Python::with_gil(|py| {
Python::attach(|py| {
bencher.iter(|| {
let vec3 = black_box(&vec3);

Expand Down
6 changes: 3 additions & 3 deletions benches/borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use pyo3::Python;

#[bench]
fn initial_shared_borrow(bencher: &mut Bencher) {
Python::with_gil(|py| {
Python::attach(|py| {
let array = PyArray::<f64, _>::zeros(py, (6, 5, 4, 3, 2, 1), false);

bencher.iter(|| {
Expand All @@ -21,7 +21,7 @@ fn initial_shared_borrow(bencher: &mut Bencher) {

#[bench]
fn additional_shared_borrow(bencher: &mut Bencher) {
Python::with_gil(|py| {
Python::attach(|py| {
let array = PyArray::<f64, _>::zeros(py, (6, 5, 4, 3, 2, 1), false);

let _shared = (0..128).map(|_| array.readonly()).collect::<Vec<_>>();
Expand All @@ -36,7 +36,7 @@ fn additional_shared_borrow(bencher: &mut Bencher) {

#[bench]
fn exclusive_borrow(bencher: &mut Bencher) {
Python::with_gil(|py| {
Python::attach(|py| {
let array = PyArray::<f64, _>::zeros(py, (6, 5, 4, 3, 2, 1), false);

bencher.iter(|| {
Expand Down
28 changes: 13 additions & 15 deletions examples/linalg/Cargo.lock

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

2 changes: 1 addition & 1 deletion examples/linalg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ name = "rust_linalg"
crate-type = ["cdylib"]

[dependencies]
pyo3 = { version = "0.25.0", features = ["extension-module"] }
pyo3 = { version = "0.26.0", features = ["extension-module"] }
numpy = { path = "../.." }
ndarray-linalg = { version = "0.14.1", features = ["openblas-system"] }

Expand Down
2 changes: 1 addition & 1 deletion examples/parallel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ name = "rust_parallel"
crate-type = ["cdylib"]

[dependencies]
pyo3 = { version = "0.25.0", features = ["extension-module", "multiple-pymethods"] }
pyo3 = { version = "0.26.0", features = ["extension-module", "multiple-pymethods"] }
numpy = { path = "../.." }
ndarray = { version = "0.16", features = ["rayon", "blas"] }
blas-src = { version = "0.8", features = ["openblas"] }
Expand Down
2 changes: 1 addition & 1 deletion examples/simple/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ name = "rust_ext"
crate-type = ["cdylib"]

[dependencies]
pyo3 = { version = "0.25.0", features = ["extension-module", "abi3-py37"] }
pyo3 = { version = "0.26.0", features = ["extension-module", "abi3-py37"] }
numpy = { path = "../.." }

[workspace]
14 changes: 7 additions & 7 deletions examples/simple/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ use numpy::{
use pyo3::{
exceptions::PyIndexError,
pymodule,
types::{PyAnyMethods, PyDict, PyDictMethods, PyModule},
Bound, FromPyObject, PyAny, PyObject, PyResult, Python,
types::{PyDict, PyDictMethods, PyModule},
Bound, FromPyObject, Py, PyAny, PyResult, Python,
};

#[pymodule]
fn rust_ext<'py>(m: &Bound<'py, PyModule>) -> PyResult<()> {
// example using generic PyObject
fn head(py: Python<'_>, x: ArrayViewD<'_, PyObject>) -> PyResult<PyObject> {
// example using generic Py<PyAny>
fn head(py: Python<'_>, x: ArrayViewD<'_, Py<PyAny>>) -> PyResult<Py<PyAny>> {
x.get(0)
.map(|obj| obj.clone_ref(py))
.ok_or_else(|| PyIndexError::new_err("array index out of range"))
Expand Down Expand Up @@ -48,7 +48,7 @@ fn rust_ext<'py>(m: &Bound<'py, PyModule>) -> PyResult<()> {
// wrapper of `head`
#[pyfn(m)]
#[pyo3(name = "head")]
fn head_py<'py>(x: PyReadonlyArrayDyn<'py, PyObject>) -> PyResult<PyObject> {
fn head_py<'py>(x: PyReadonlyArrayDyn<'py, Py<PyAny>>) -> PyResult<Py<PyAny>> {
head(x.py(), x.as_array())
}

Expand Down Expand Up @@ -92,7 +92,7 @@ fn rust_ext<'py>(m: &Bound<'py, PyModule>) -> PyResult<()> {
.get_item("x")
.unwrap()
.unwrap()
.downcast_into::<PyArray1<f64>>()
.cast_into::<PyArray1<f64>>()
.unwrap();

x.readonly().as_array().sum()
Expand Down Expand Up @@ -141,7 +141,7 @@ fn rust_ext<'py>(m: &Bound<'py, PyModule>) -> PyResult<()> {
.into_any()),
(SupportedArray::F64(x), SupportedArray::I64(y))
| (SupportedArray::I64(y), SupportedArray::F64(x)) => {
let y = y.cast::<f64>(false)?;
let y = y.cast_array::<f64>(false)?;

Ok(
generic_add(x.readonly().as_array(), y.readonly().as_array())
Expand Down
Loading
Loading