Skip to content
Draft
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Changelog
- v0.27.0
- Bump PyO3 dependency to v0.27.0. ([#xxx](https://github.com/PyO3/rust-numpy/pull/xxx))

- 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))
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "numpy"
version = "0.26.0"
version = "0.27.0"
authors = [
"The rust-numpy Project Developers",
"PyO3 Project and Contributors <https://github.com/PyO3>",
Expand All @@ -22,13 +22,13 @@ num-complex = ">= 0.2, < 0.5"
num-integer = "0.1"
num-traits = "0.2"
ndarray = ">= 0.15, < 0.17"
pyo3 = { version = "0.26.0", default-features = false, features = ["macros"]}
pyo3 = { version = "0.26.0", default-features = false, features = ["macros"], path = "../pyo3"}
rustc-hash = "2.0"

[dev-dependencies]
pyo3 = { version = "0.26.0", default-features = false, features = [
"auto-initialize",
] }
], path = "../pyo3" }
nalgebra = { version = ">=0.30, <0.35", default-features = false, features = [
"std",
] }
Expand Down
32 changes: 14 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ rust-numpy
===========
[![Actions Status](https://github.com/PyO3/rust-numpy/workflows/CI/badge.svg)](https://github.com/PyO3/rust-numpy/actions)
[![Crate](https://img.shields.io/crates/v/numpy.svg)](https://crates.io/crates/numpy)
[![Minimum rustc 1.63](https://img.shields.io/badge/rustc-1.63+-blue.svg)](https://rust-lang.github.io/rfcs/2495-min-rust-version.html)
[![Minimum rustc 1.74](https://img.shields.io/badge/rustc-1.74+-blue.svg)](https://rust-lang.github.io/rfcs/2495-min-rust-version.html)
[![Documentation](https://docs.rs/numpy/badge.svg)](https://docs.rs/numpy)
[![codecov](https://codecov.io/gh/PyO3/rust-numpy/branch/main/graph/badge.svg)](https://codecov.io/gh/PyO3/rust-numpy)

Expand All @@ -13,7 +13,7 @@ Rust bindings for the NumPy C-API.
- [Current main](https://pyo3.github.io/rust-numpy)

## Requirements
- Rust >= 1.63.0
- Rust >= 1.74.0
- Basically, our MSRV follows the one of [PyO3](https://github.com/PyO3/pyo3)
- Python >= 3.7
- Python 3.6 support was dropped from 0.16
Expand All @@ -38,17 +38,17 @@ name = "rust_ext"
crate-type = ["cdylib"]

[dependencies]
pyo3 = { version = "0.22", features = ["extension-module"] }
numpy = "0.22"
pyo3 = { version = "0.27", features = ["extension-module"] }
numpy = "0.27"
```

```rust
use numpy::ndarray::{ArrayD, ArrayViewD, ArrayViewMutD};
use numpy::{IntoPyArray, PyArrayDyn, PyReadonlyArrayDyn, PyArrayMethods};
use pyo3::{pymodule, types::PyModule, PyResult, Python, Bound};
#[pyo3::pymodule]
mod rust_ext {
use numpy::ndarray::{ArrayD, ArrayViewD, ArrayViewMutD};
use numpy::{IntoPyArray, PyArrayDyn, PyReadonlyArrayDyn, PyArrayMethods};
use pyo3::{pyfunction, PyResult, Python, Bound};

#[pymodule]
fn rust_ext<'py>(_py: Python<'py>, m: &Bound<'py, PyModule>) -> PyResult<()> {
// example using immutable borrows producing a new array
fn axpy(a: f64, x: ArrayViewD<'_, f64>, y: ArrayViewD<'_, f64>) -> ArrayD<f64> {
a * &x + &y
Expand All @@ -60,8 +60,7 @@ fn rust_ext<'py>(_py: Python<'py>, m: &Bound<'py, PyModule>) -> PyResult<()> {
}

// wrapper of `axpy`
#[pyfn(m)]
#[pyo3(name = "axpy")]
#[pyfunction(name = "axpy")]
fn axpy_py<'py>(
py: Python<'py>,
a: f64,
Expand All @@ -75,14 +74,11 @@ fn rust_ext<'py>(_py: Python<'py>, m: &Bound<'py, PyModule>) -> PyResult<()> {
}

// wrapper of `mult`
#[pyfn(m)]
#[pyo3(name = "mult")]
#[pyfunction(name = "mult")]
fn mult_py<'py>(a: f64, x: &Bound<'py, PyArrayDyn<f64>>) {
let x = unsafe { x.as_array_mut() };
mult(a, x);
}

Ok(())
}
```

Expand All @@ -93,8 +89,8 @@ fn rust_ext<'py>(_py: Python<'py>, m: &Bound<'py, PyModule>) -> PyResult<()> {
name = "numpy-test"

[dependencies]
pyo3 = { version = "0.22", features = ["auto-initialize"] }
numpy = "0.22"
pyo3 = { version = "0.27", features = ["auto-initialize"] }
numpy = "0.27"
```

```rust
Expand Down Expand Up @@ -132,7 +128,7 @@ on anything but that exact range. It can therefore be necessary to manually unif
For example, if you specify the following dependencies

```toml
numpy = "0.22"
numpy = "0.27"
ndarray = "0.15"
```

Expand Down
4 changes: 2 additions & 2 deletions benches/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn extract_success(bencher: &mut Bencher) {
#[bench]
fn extract_failure(bencher: &mut Bencher) {
Python::attach(|py| {
let any = PyArray2::<f64>::zeros(py, (10, 10), false).into_any();
let any = PyArray2::<i32>::zeros(py, (10, 10), false).into_any();

bencher.iter(|| {
black_box(&any)
Expand All @@ -46,7 +46,7 @@ fn cast_success(bencher: &mut Bencher) {
#[bench]
fn cast_failure(bencher: &mut Bencher) {
Python::attach(|py| {
let any = PyArray2::<f64>::zeros(py, (10, 10), false).into_any();
let any = PyArray2::<i32>::zeros(py, (10, 10), false).into_any();

bencher.iter(|| black_box(&any).cast::<PyArray2<f64>>().unwrap_err());
});
Expand Down
23 changes: 11 additions & 12 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.26.0", features = ["extension-module"] }
pyo3 = { version = "0.26.0", features = ["extension-module"], path = "../../../pyo3" }
numpy = { path = "../.." }
ndarray-linalg = { version = "0.14.1", features = ["openblas-system"] }

Expand Down
13 changes: 6 additions & 7 deletions examples/linalg/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use ndarray_linalg::solve::Inverse;
use numpy::{IntoPyArray, PyArray2, PyReadonlyArray2};
use pyo3::{exceptions::PyRuntimeError, pymodule, types::PyModule, Bound, PyResult, Python};
#[pyo3::pymodule]
mod rust_linalg {
use ndarray_linalg::solve::Inverse;
use numpy::{IntoPyArray, PyArray2, PyReadonlyArray2};
use pyo3::{exceptions::PyRuntimeError, pyfunction, Bound, PyResult, Python};

#[pymodule]
fn rust_linalg<'py>(m: &Bound<'py, PyModule>) -> PyResult<()> {
#[pyfn(m)]
#[pyfunction]
fn inv<'py>(
py: Python<'py>,
x: PyReadonlyArray2<'py, f64>,
Expand All @@ -15,5 +15,4 @@ fn rust_linalg<'py>(m: &Bound<'py, PyModule>) -> PyResult<()> {
.map_err(|e| PyRuntimeError::new_err(e.to_string()))?;
Ok(y.into_pyarray(py))
}
Ok(())
}
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.26.0", features = ["extension-module", "multiple-pymethods"] }
pyo3 = { version = "0.26.0", features = ["extension-module", "multiple-pymethods"], path = "../../../pyo3"}
numpy = { path = "../.." }
ndarray = { version = "0.16", features = ["rayon", "blas"] }
blas-src = { version = "0.8", features = ["openblas"] }
Expand Down
13 changes: 6 additions & 7 deletions examples/parallel/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// We need to link `blas_src` directly, c.f. https://github.com/rust-ndarray/ndarray#how-to-enable-blas-integration
extern crate blas_src;

use numpy::ndarray::Zip;
use numpy::{IntoPyArray, PyArray1, PyReadonlyArray1, PyReadonlyArray2};
use pyo3::{pymodule, types::PyModule, Bound, PyResult, Python};
#[pyo3::pymodule]
mod rust_parallel {
use numpy::ndarray::Zip;
use numpy::{IntoPyArray, PyArray1, PyReadonlyArray1, PyReadonlyArray2};
use pyo3::{pyfunction, Bound, PyResult, Python};

#[pymodule]
fn rust_parallel<'py>(m: &Bound<'py, PyModule>) -> PyResult<()> {
#[pyfn(m)]
#[pyfunction]
fn rows_dot<'py>(
py: Python<'py>,
x: PyReadonlyArray2<'py, f64>,
Expand All @@ -18,5 +18,4 @@ fn rust_parallel<'py>(m: &Bound<'py, PyModule>) -> PyResult<()> {
let z = Zip::from(x.rows()).par_map_collect(|row| row.dot(&y));
z.into_pyarray(py)
}
Ok(())
}
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.26.0", features = ["extension-module", "abi3-py37"] }
pyo3 = { version = "0.26.0", features = ["extension-module", "abi3-py37"], path = "../../../pyo3"}
numpy = { path = "../.." }

[workspace]
51 changes: 22 additions & 29 deletions examples/simple/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
use std::ops::Add;
#[pyo3::pymodule]
mod rust_ext {
use numpy::ndarray::{Array1, ArrayD, ArrayView1, ArrayViewD, ArrayViewMutD, Zip};
use numpy::{
datetime::{units, Timedelta},
Complex64, IntoPyArray, PyArray1, PyArrayDyn, PyArrayMethods, PyReadonlyArray1,
PyReadonlyArrayDyn, PyReadwriteArray1, PyReadwriteArrayDyn,
};
use pyo3::{
exceptions::PyIndexError,
pyfunction,
types::{PyDict, PyDictMethods},
Bound, FromPyObject, Py, PyAny, PyResult, Python,
};
use std::ops::Add;

use numpy::ndarray::{Array1, ArrayD, ArrayView1, ArrayViewD, ArrayViewMutD, Zip};
use numpy::{
datetime::{units, Timedelta},
Complex64, IntoPyArray, PyArray1, PyArrayDyn, PyArrayMethods, PyReadonlyArray1,
PyReadonlyArrayDyn, PyReadwriteArray1, PyReadwriteArrayDyn,
};
use pyo3::{
exceptions::PyIndexError,
pymodule,
types::{PyDict, PyDictMethods, PyModule},
Bound, FromPyObject, Py, PyAny, PyResult, Python,
};

#[pymodule]
fn rust_ext<'py>(m: &Bound<'py, PyModule>) -> PyResult<()> {
// example using generic Py<PyAny>
fn head(py: Python<'_>, x: ArrayViewD<'_, Py<PyAny>>) -> PyResult<Py<PyAny>> {
x.get(0)
Expand Down Expand Up @@ -46,15 +45,13 @@ fn rust_ext<'py>(m: &Bound<'py, PyModule>) -> PyResult<()> {
}

// wrapper of `head`
#[pyfn(m)]
#[pyo3(name = "head")]
#[pyfunction(name = "head")]
fn head_py<'py>(x: PyReadonlyArrayDyn<'py, Py<PyAny>>) -> PyResult<Py<PyAny>> {
head(x.py(), x.as_array())
}

// wrapper of `axpy`
#[pyfn(m)]
#[pyo3(name = "axpy")]
#[pyfunction(name = "axpy")]
fn axpy_py<'py>(
py: Python<'py>,
a: f64,
Expand All @@ -68,16 +65,14 @@ fn rust_ext<'py>(m: &Bound<'py, PyModule>) -> PyResult<()> {
}

// wrapper of `mult`
#[pyfn(m)]
#[pyo3(name = "mult")]
#[pyfunction(name = "mult")]
fn mult_py<'py>(a: f64, mut x: PyReadwriteArrayDyn<'py, f64>) {
let x = x.as_array_mut();
mult(a, x);
}

// wrapper of `conj`
#[pyfn(m)]
#[pyo3(name = "conj")]
#[pyfunction(name = "conj")]
fn conj_py<'py>(
py: Python<'py>,
x: PyReadonlyArrayDyn<'py, Complex64>,
Expand All @@ -86,7 +81,7 @@ fn rust_ext<'py>(m: &Bound<'py, PyModule>) -> PyResult<()> {
}

// example of how to extract an array from a dictionary
#[pyfn(m)]
#[pyfunction]
fn extract(d: &Bound<'_, PyDict>) -> f64 {
let x = d
.get_item("x")
Expand All @@ -99,7 +94,7 @@ fn rust_ext<'py>(m: &Bound<'py, PyModule>) -> PyResult<()> {
}

// example using timedelta64 array
#[pyfn(m)]
#[pyfunction]
fn add_minutes_to_seconds<'py>(
mut x: PyReadwriteArray1<'py, Timedelta<units::Seconds>>,
y: PyReadonlyArray1<'py, Timedelta<units::Minutes>>,
Expand All @@ -121,7 +116,7 @@ fn rust_ext<'py>(m: &Bound<'py, PyModule>) -> PyResult<()> {
I64(Bound<'py, PyArray1<i64>>),
}

#[pyfn(m)]
#[pyfunction]
fn polymorphic_add<'py>(
x: SupportedArray<'py>,
y: SupportedArray<'py>,
Expand Down Expand Up @@ -151,6 +146,4 @@ fn rust_ext<'py>(m: &Bound<'py, PyModule>) -> PyResult<()> {
}
}
}

Ok(())
}
Loading
Loading