Skip to content

Commit

Permalink
Remove unneeded lifetime annotations (#389)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hofer-Julian committed Sep 8, 2023
1 parent 3843fa9 commit 3a18675
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions examples/linalg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use numpy::{IntoPyArray, PyArray2, PyReadonlyArray2};
use pyo3::{exceptions::PyRuntimeError, pymodule, types::PyModule, PyResult, Python};

#[pymodule]
fn rust_linalg(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
fn rust_linalg(_py: Python, m: &PyModule) -> PyResult<()> {
#[pyfn(m)]
fn inv<'py>(py: Python<'py>, x: PyReadonlyArray2<'py, f64>) -> PyResult<&'py PyArray2<f64>> {
fn inv<'py>(py: Python<'py>, x: PyReadonlyArray2<f64>) -> PyResult<&'py PyArray2<f64>> {
let x = x.as_array();
let y = x
.inv()
Expand Down
6 changes: 3 additions & 3 deletions examples/parallel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use numpy::{IntoPyArray, PyArray1, PyReadonlyArray1, PyReadonlyArray2};
use pyo3::{pymodule, types::PyModule, PyResult, Python};

#[pymodule]
fn rust_parallel(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
fn rust_parallel(_py: Python, m: &PyModule) -> PyResult<()> {
#[pyfn(m)]
fn rows_dot<'py>(
py: Python<'py>,
x: PyReadonlyArray2<'py, f64>,
y: PyReadonlyArray1<'py, f64>,
x: PyReadonlyArray2<f64>,
y: PyReadonlyArray1<f64>,
) -> &'py PyArray1<f64> {
let x = x.as_array();
let y = y.as_array();
Expand Down
18 changes: 9 additions & 9 deletions examples/simple/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@ use pyo3::{
};

#[pymodule]
fn rust_ext(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
fn rust_ext(_py: Python, m: &PyModule) -> PyResult<()> {
// example using generic PyObject
fn head(x: ArrayViewD<'_, PyObject>) -> PyResult<PyObject> {
fn head(x: ArrayViewD<PyObject>) -> PyResult<PyObject> {
x.get(0)
.cloned()
.ok_or_else(|| PyIndexError::new_err("array index out of range"))
}

// example using immutable borrows producing a new array
fn axpy(a: f64, x: ArrayViewD<'_, f64>, y: ArrayViewD<'_, f64>) -> ArrayD<f64> {
fn axpy(a: f64, x: ArrayViewD<f64>, y: ArrayViewD<f64>) -> ArrayD<f64> {
a * &x + &y
}

// example using a mutable borrow to modify an array in-place
fn mult(a: f64, mut x: ArrayViewMutD<'_, f64>) {
fn mult(a: f64, mut x: ArrayViewMutD<f64>) {
x *= a;
}

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

Expand All @@ -45,7 +45,7 @@ fn rust_ext(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
// wrapper of `head`
#[pyfn(m)]
#[pyo3(name = "head")]
fn head_py(_py: Python<'_>, x: PyReadonlyArrayDyn<'_, PyObject>) -> PyResult<PyObject> {
fn head_py(_py: Python, x: PyReadonlyArrayDyn<PyObject>) -> PyResult<PyObject> {
head(x.as_array())
}

Expand All @@ -55,8 +55,8 @@ fn rust_ext(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
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 @@ -77,7 +77,7 @@ fn rust_ext(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
#[pyo3(name = "conj")]
fn conj_py<'py>(
py: Python<'py>,
x: PyReadonlyArrayDyn<'_, Complex64>,
x: PyReadonlyArrayDyn<Complex64>,
) -> &'py PyArrayDyn<Complex64> {
conj(x.as_array()).into_pyarray(py)
}
Expand Down
1 change: 1 addition & 0 deletions tests/to_py.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use pyo3::{
#[test]
fn to_pyarray_vec() {
Python::with_gil(|py| {
#[allow(clippy::useless_vec)]
let arr = vec![1, 2, 3].to_pyarray(py);

assert_eq!(arr.shape(), [3]);
Expand Down

0 comments on commit 3a18675

Please sign in to comment.