Skip to content

Commit 2976137

Browse files
authored
Merge pull request #68 from kngwyu/to-pyarray
Fix memory leak
2 parents e372f0b + 9c4dcec commit 2976137

File tree

10 files changed

+446
-236
lines changed

10 files changed

+446
-236
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ license-file = "LICENSE"
1313
cfg-if = "0.1.5"
1414
libc = "0.2"
1515
num-complex = "0.2"
16+
num-traits = "0.2.6"
1617
ndarray = "0.12"
1718
pyo3 = "0.4.1"

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ crate-type = ["cdylib"]
8282

8383
[dependencies]
8484
numpy = "0.3"
85-
ndarray = "0.11"
85+
ndarray = "0.12"
8686

8787
[dependencies.pyo3]
8888
version = "^0.4.1"
@@ -95,7 +95,7 @@ extern crate numpy;
9595
extern crate pyo3;
9696

9797
use ndarray::{ArrayD, ArrayViewD, ArrayViewMutD};
98-
use numpy::{IntoPyArray, IntoPyResult, PyArray};
98+
use numpy::{IntoPyResult, PyArray, ToPyArray};
9999
use pyo3::prelude::{pymodinit, PyModule, PyResult, Python};
100100

101101
#[pymodinit]
@@ -115,7 +115,7 @@ fn rust_ext(_py: Python, m: &PyModule) -> PyResult<()> {
115115
fn axpy_py(py: Python, a: f64, x: &PyArray<f64>, y: &PyArray<f64>) -> PyResult<PyArray<f64>> {
116116
let x = x.as_array().into_pyresult("x must be f64 array")?;
117117
let y = y.as_array().into_pyresult("y must be f64 array")?;
118-
Ok(axpy(a, x, y).into_pyarray(py).to_owned(py))
118+
Ok(axpy(a, x, y).to_pyarray(py).to_owned(py))
119119
}
120120

121121
// wrapper of `mult`

example/extensions/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ crate-type = ["cdylib"]
99

1010
[dependencies]
1111
numpy = { path = "../.." }
12-
ndarray = ">= 0.11"
12+
ndarray = "0.12"
1313

1414
[dependencies.pyo3]
1515
version = "0.4.1"

example/extensions/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ extern crate numpy;
33
extern crate pyo3;
44

55
use ndarray::{ArrayD, ArrayViewD, ArrayViewMutD};
6-
use numpy::{IntoPyArray, IntoPyResult, PyArray};
6+
use numpy::{IntoPyResult, PyArray, ToPyArray};
77
use pyo3::prelude::{pymodinit, PyModule, PyResult, Python};
88

99
#[pymodinit]
@@ -23,7 +23,7 @@ fn rust_ext(_py: Python, m: &PyModule) -> PyResult<()> {
2323
fn axpy_py(py: Python, a: f64, x: &PyArray<f64>, y: &PyArray<f64>) -> PyResult<PyArray<f64>> {
2424
let x = x.as_array().into_pyresult("x must be f64 array")?;
2525
let y = y.as_array().into_pyresult("y must be f64 array")?;
26-
Ok(axpy(a, x, y).into_pyarray(py).to_owned(py))
26+
Ok(axpy(a, x, y).to_pyarray(py).to_owned(py))
2727
}
2828

2929
// wrapper of `mult`

0 commit comments

Comments
 (0)