Skip to content

Relax MSRV version to 1.41.1 and test it in CI #177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 16, 2021
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
38 changes: 37 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,43 @@ jobs:
env:
RUST_BACKTRACE: 1

check-msrv:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install MSRV Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.41.1
- name: Install maturin, poetry, and toml
run: pip install maturin poetry toml
- name: Create an isolated example directory
run: cp -r examples/simple-extension/ ../simple-extension-msrv
- name: Edit Cargo.toml
run: |
import toml
cargo_toml = toml.load("Cargo.toml")
cargo_toml["dependencies"]["ndarray"] = "0.13.1"
cargo_toml["dependencies"]["num-complex"] = "0.2.4"
cargo_toml["dependencies"]["numpy"]["path"] = "../rust-numpy"
with open("Cargo.toml", "w") as f:
toml.dump(cargo_toml, f)
working-directory: ../simple-extension-msrv
shell: python
- name: Remove ndarray 0.14.0
run: cargo update -p ndarray:0.14.0 --precise 0.13.1
working-directory: ../simple-extension-msrv
- name: Test Example
run: |
poetry install && poetry run maturin develop && poetry run pytest
working-directory: ../simple-extension-msrv
shell: bash

linalg-example:
runs-on: ubuntu-latest
steps:
Expand All @@ -85,7 +122,6 @@ jobs:
uses: actions-rs/toolchain@v1
with:
toolchain: stable
default: true
- name: Install maturin and poetry
run: pip install maturin poetry
- name: Test Examples
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ license-file = "LICENSE"
[dependencies]
cfg-if = "0.1"
libc = "0.2"
num-complex = "0.3"
num-complex = ">= 0.2, < 0.4"
num-traits = "0.2"
ndarray = "0.14"
ndarray = ">= 0.13, < 0.15"
pyo3 = "0.13"

[features]
Expand Down
7 changes: 4 additions & 3 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](http://meritbadge.herokuapp.com/numpy)](https://crates.io/crates/numpy)
[![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)
[![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)

Rust bindings for the NumPy C-API

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


## Requirements
- Rust 1.39+
- Rust >= 1.41.1
- Basically, our MSRV follows the one of [PyO3](https://github.com/PyO3/pyo3).
- Python >= 3.6
- Python 3.5 support is dropped from 0.13
- Some Rust libraries
- [ndarray](https://github.com/bluss/ndarray) for rust-side matrix library
- [pyo3](https://github.com/PyO3/pyo3) for cpython binding
- [PyO3](https://github.com/PyO3/pyo3) for cpython binding
- and more (see [Cargo.toml](Cargo.toml))
- [numpy](http://www.numpy.org/) installed in your python environments (e.g., via `pip install numpy`)
- We recommend `numpy >= 1.16.0`, though older version may work.
Expand Down
2 changes: 1 addition & 1 deletion examples/linalg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ crate-type = ["cdylib"]
[dependencies]
numpy = { path = "../.." }
ndarray = "0.14"
ndarray-linalg = { git = "https://github.com/kngwyu/ndarray-linalg", branch = "ndarray-014", features = ["openblas-static"] }
ndarray-linalg = { version = "0.13", features = ["openblas-static"] }

[dependencies.pyo3]
version = "0.13"
Expand Down
1 change: 1 addition & 0 deletions examples/simple-extension/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ crate-type = ["cdylib"]
[dependencies]
numpy = { path = "../.." }
ndarray = "0.14"
num-complex = "0.3"

[dependencies.pyo3]
version = "0.13"
Expand Down
20 changes: 15 additions & 5 deletions examples/simple-extension/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ndarray::{ArrayD, ArrayViewD, ArrayViewMutD};
use numpy::{IntoPyArray, PyArrayDyn, PyReadonlyArrayDyn};
use numpy::{c64, IntoPyArray, PyArrayDyn, PyReadonlyArrayDyn};
use pyo3::prelude::{pymodule, PyModule, PyResult, Python};

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

// complex example
fn conj(x: ArrayViewD<'_, c64>) -> ArrayD<c64> {
x.map(|c| c.conj())
}

// wrapper of `axpy`
#[pyfn(m, "axpy")]
fn axpy_py<'py>(
py: Python<'py>,
a: f64,
x: PyReadonlyArrayDyn<f64>,
y: PyReadonlyArrayDyn<f64>,
x: PyReadonlyArrayDyn<'_, f64>,
y: PyReadonlyArrayDyn<'_, f64>,
) -> &'py PyArrayDyn<f64> {
let x = x.as_array();
let y = y.as_array();
Expand All @@ -29,10 +34,15 @@ fn rust_ext(_py: Python<'_>, m: &PyModule) -> PyResult<()> {

// wrapper of `mult`
#[pyfn(m, "mult")]
fn mult_py(_py: Python<'_>, a: f64, x: &PyArrayDyn<f64>) -> PyResult<()> {
fn mult_py(a: f64, x: &PyArrayDyn<f64>) {
let x = unsafe { x.as_array_mut() };
mult(a, x);
Ok(())
}

// wrapper of `conj`
#[pyfn(m, "conj")]
fn conj_py<'py>(py: Python<'py>, x: PyReadonlyArrayDyn<'_, c64>) -> &'py PyArrayDyn<c64> {
conj(x.as_array()).into_pyarray(py)
}

Ok(())
Expand Down
7 changes: 6 additions & 1 deletion examples/simple-extension/tests/test_ext.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
from rust_ext import axpy, mult
from rust_ext import axpy, conj, mult


def test_axpy():
Expand All @@ -17,3 +17,8 @@ def test_mult():
x = np.array([1.0, 2.0, 3.0])
mult(3.0, x)
np.testing.assert_array_almost_equal(x, np.array([3.0, 6.0, 9.0]))


def test_conj():
x = np.array([1.0 + 2j, 2.0 + 3j, 3.0 + 4j])
np.testing.assert_array_almost_equal(conj(x), np.conj(x))
Empty file modified src/lib.rs
100755 → 100644
Empty file.