Skip to content

Commit cfe630f

Browse files
committed
Update numpy-linalg-example with maturin and poetry
1 parent ee1a54b commit cfe630f

File tree

8 files changed

+270
-53
lines changed

8 files changed

+270
-53
lines changed

examples/linalg/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "numpy-linalg-example"
33
version = "0.1.0"
4-
authors = ["kngwyu <[email protected]>"]
4+
authors = ["Yuji Kanagawa <[email protected]>"]
55
edition = "2018"
66

77
[lib]
@@ -11,7 +11,7 @@ crate-type = ["cdylib"]
1111
[dependencies]
1212
numpy = { path = "../.." }
1313
ndarray = ">= 0.13"
14-
ndarray-linalg = { version = "0.12", features = ["openblas"] }
14+
ndarray-linalg = { version = "0.12.1", features = ["openblas-static"] }
1515

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

examples/linalg/poetry.lock

Lines changed: 244 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/linalg/pyproject.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[build-system]
2+
build-backend = "maturin"
3+
4+
[tool.poetry]
5+
name = "numpy-linalg-example"
6+
version = "0.1.0"
7+
description = "rust-numpy example with ndarray-linalg"
8+
authors = ["Yuji Kanagawa <[email protected]>"]
9+
10+
[tool.poetry.dependencies]
11+
numpy = ">=1.18"
12+
python = ">=3.6"
13+
14+
[tool.poetry.dev-dependencies]
15+
pytest = "^6.1"

examples/linalg/requirements-dev.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

examples/linalg/rust_linalg/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/linalg/setup.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

examples/linalg/src/lib.rs

100644100755
Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1-
#![deny(rust_2018_idioms)]
21
use ndarray_linalg::solve::Inverse;
3-
use numpy::{IntoPyArray, PyArray2};
4-
use pyo3::exceptions::RuntimeError;
5-
use pyo3::prelude::{pymodule, Py, PyErr, PyModule, PyResult, Python};
6-
use std::fmt::Display;
7-
8-
fn make_error<E: Display + Sized>(e: E) -> PyErr {
9-
PyErr::new::<RuntimeError, _>(format!("[rust_linalg] {}", e))
10-
}
2+
use numpy::{IntoPyArray, PyArray2, PyReadonlyArray2};
3+
use pyo3::exceptions::PyRuntimeError;
4+
use pyo3::prelude::{pymodule, PyErr, PyModule, PyResult, Python};
115

126
#[pymodule]
137
fn rust_linalg(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
148
#[pyfn(m, "inv")]
15-
fn inv(py: Python<'_>, x: &PyArray2<f64>) -> PyResult<Py<PyArray2<f64>>> {
16-
let x = x.as_array().inv().map_err(make_error)?;
17-
Ok(x.into_pyarray(py).to_owned())
9+
fn inv<'py>(py: Python<'py>, x: PyReadonlyArray2<'py, f64>) -> PyResult<&'py PyArray2<f64>> {
10+
let x = x
11+
.as_array()
12+
.inv()
13+
.map_err(|e| PyErr::new::<PyRuntimeError, _>(format!("[rust_linalg] {}", e)))?;
14+
Ok(x.into_pyarray(py))
1815
}
1916
Ok(())
2017
}

examples/linalg/tox.ini

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)