Skip to content

Commit 7194f44

Browse files
authored
Merge pull request #177 from PyO3/update-msrv
Relax MSRV version to 1.41.1 and test it in CI
2 parents a5e0b28 + d883802 commit 7194f44

File tree

8 files changed

+66
-13
lines changed

8 files changed

+66
-13
lines changed

.github/workflows/ci.yml

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,43 @@ jobs:
7070
env:
7171
RUST_BACKTRACE: 1
7272

73+
check-msrv:
74+
runs-on: ubuntu-latest
75+
steps:
76+
- uses: actions/checkout@v2
77+
- name: Set up Python
78+
uses: actions/setup-python@v2
79+
with:
80+
python-version: 3.8
81+
- name: Install MSRV Rust
82+
uses: actions-rs/toolchain@v1
83+
with:
84+
profile: minimal
85+
toolchain: 1.41.1
86+
- name: Install maturin, poetry, and toml
87+
run: pip install maturin poetry toml
88+
- name: Create an isolated example directory
89+
run: cp -r examples/simple-extension/ ../simple-extension-msrv
90+
- name: Edit Cargo.toml
91+
run: |
92+
import toml
93+
cargo_toml = toml.load("Cargo.toml")
94+
cargo_toml["dependencies"]["ndarray"] = "0.13.1"
95+
cargo_toml["dependencies"]["num-complex"] = "0.2.4"
96+
cargo_toml["dependencies"]["numpy"]["path"] = "../rust-numpy"
97+
with open("Cargo.toml", "w") as f:
98+
toml.dump(cargo_toml, f)
99+
working-directory: ../simple-extension-msrv
100+
shell: python
101+
- name: Remove ndarray 0.14.0
102+
run: cargo update -p ndarray:0.14.0 --precise 0.13.1
103+
working-directory: ../simple-extension-msrv
104+
- name: Test Example
105+
run: |
106+
poetry install && poetry run maturin develop && poetry run pytest
107+
working-directory: ../simple-extension-msrv
108+
shell: bash
109+
73110
linalg-example:
74111
runs-on: ubuntu-latest
75112
steps:
@@ -85,7 +122,6 @@ jobs:
85122
uses: actions-rs/toolchain@v1
86123
with:
87124
toolchain: stable
88-
default: true
89125
- name: Install maturin and poetry
90126
run: pip install maturin poetry
91127
- name: Test Examples

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ license-file = "LICENSE"
1212
[dependencies]
1313
cfg-if = "0.1"
1414
libc = "0.2"
15-
num-complex = "0.3"
15+
num-complex = ">= 0.2, < 0.4"
1616
num-traits = "0.2"
17-
ndarray = "0.14"
17+
ndarray = ">= 0.13, < 0.15"
1818
pyo3 = "0.13"
1919

2020
[features]

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ rust-numpy
22
===========
33
[![Actions Status](https://github.com/pyo3/rust-numpy/workflows/CI/badge.svg)](https://github.com/pyo3/rust-numpy/actions)
44
[![Crate](http://meritbadge.herokuapp.com/numpy)](https://crates.io/crates/numpy)
5-
[![minimum rustc 1.39](https://img.shields.io/badge/rustc-1.39+-blue.svg)](https://rust-lang.github.io/rfcs/2495-min-rust-version.html)
5+
[![minimum rustc 1.41](https://img.shields.io/badge/rustc-1.41+-blue.svg)](https://rust-lang.github.io/rfcs/2495-min-rust-version.html)
66

77
Rust bindings for the NumPy C-API
88

@@ -12,12 +12,13 @@ Rust bindings for the NumPy C-API
1212

1313

1414
## Requirements
15-
- Rust 1.39+
15+
- Rust >= 1.41.1
16+
- Basically, our MSRV follows the one of [PyO3](https://github.com/PyO3/pyo3).
1617
- Python >= 3.6
1718
- Python 3.5 support is dropped from 0.13
1819
- Some Rust libraries
1920
- [ndarray](https://github.com/bluss/ndarray) for rust-side matrix library
20-
- [pyo3](https://github.com/PyO3/pyo3) for cpython binding
21+
- [PyO3](https://github.com/PyO3/pyo3) for cpython binding
2122
- and more (see [Cargo.toml](Cargo.toml))
2223
- [numpy](http://www.numpy.org/) installed in your python environments (e.g., via `pip install numpy`)
2324
- We recommend `numpy >= 1.16.0`, though older version may work.

examples/linalg/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ crate-type = ["cdylib"]
1111
[dependencies]
1212
numpy = { path = "../.." }
1313
ndarray = "0.14"
14-
ndarray-linalg = { git = "https://github.com/kngwyu/ndarray-linalg", branch = "ndarray-014", features = ["openblas-static"] }
14+
ndarray-linalg = { version = "0.13", features = ["openblas-static"] }
1515

1616
[dependencies.pyo3]
1717
version = "0.13"

examples/simple-extension/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ crate-type = ["cdylib"]
1111
[dependencies]
1212
numpy = { path = "../.." }
1313
ndarray = "0.14"
14+
num-complex = "0.3"
1415

1516
[dependencies.pyo3]
1617
version = "0.13"

examples/simple-extension/src/lib.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use ndarray::{ArrayD, ArrayViewD, ArrayViewMutD};
2-
use numpy::{IntoPyArray, PyArrayDyn, PyReadonlyArrayDyn};
2+
use numpy::{c64, IntoPyArray, PyArrayDyn, PyReadonlyArrayDyn};
33
use pyo3::prelude::{pymodule, PyModule, PyResult, Python};
44

55
#[pymodule]
@@ -14,13 +14,18 @@ fn rust_ext(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
1414
x *= a;
1515
}
1616

17+
// complex example
18+
fn conj(x: ArrayViewD<'_, c64>) -> ArrayD<c64> {
19+
x.map(|c| c.conj())
20+
}
21+
1722
// wrapper of `axpy`
1823
#[pyfn(m, "axpy")]
1924
fn axpy_py<'py>(
2025
py: Python<'py>,
2126
a: f64,
22-
x: PyReadonlyArrayDyn<f64>,
23-
y: PyReadonlyArrayDyn<f64>,
27+
x: PyReadonlyArrayDyn<'_, f64>,
28+
y: PyReadonlyArrayDyn<'_, f64>,
2429
) -> &'py PyArrayDyn<f64> {
2530
let x = x.as_array();
2631
let y = y.as_array();
@@ -29,10 +34,15 @@ fn rust_ext(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
2934

3035
// wrapper of `mult`
3136
#[pyfn(m, "mult")]
32-
fn mult_py(_py: Python<'_>, a: f64, x: &PyArrayDyn<f64>) -> PyResult<()> {
37+
fn mult_py(a: f64, x: &PyArrayDyn<f64>) {
3338
let x = unsafe { x.as_array_mut() };
3439
mult(a, x);
35-
Ok(())
40+
}
41+
42+
// wrapper of `conj`
43+
#[pyfn(m, "conj")]
44+
fn conj_py<'py>(py: Python<'py>, x: PyReadonlyArrayDyn<'_, c64>) -> &'py PyArrayDyn<c64> {
45+
conj(x.as_array()).into_pyarray(py)
3646
}
3747

3848
Ok(())

examples/simple-extension/tests/test_ext.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import numpy as np
2-
from rust_ext import axpy, mult
2+
from rust_ext import axpy, conj, mult
33

44

55
def test_axpy():
@@ -17,3 +17,8 @@ def test_mult():
1717
x = np.array([1.0, 2.0, 3.0])
1818
mult(3.0, x)
1919
np.testing.assert_array_almost_equal(x, np.array([3.0, 6.0, 9.0]))
20+
21+
22+
def test_conj():
23+
x = np.array([1.0 + 2j, 2.0 + 3j, 3.0 + 4j])
24+
np.testing.assert_array_almost_equal(conj(x), np.conj(x))

src/lib.rs

100755100644
File mode changed.

0 commit comments

Comments
 (0)