Skip to content

Commit efae36c

Browse files
Merge pull request #945 from LaurentMazare/update-pyo3-dependency
Update the pyo3 dependency.
2 parents 55dd5b4 + 2884052 commit efae36c

File tree

5 files changed

+14
-9
lines changed

5 files changed

+14
-9
lines changed

examples/python-extension/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ name = "tch_ext"
1717
crate-type = ["cdylib"]
1818

1919
[dependencies]
20-
pyo3 = { version = "0.21", features = ["extension-module"] }
20+
pyo3 = { version = "0.24", features = ["extension-module"] }
2121
pyo3-tch = { path = "../../pyo3-tch", version = "0.19.0" }
2222
tch = { path = "../..", features = ["python-extension"], version = "0.19.0" }
2323
torch-sys = { path = "../../torch-sys", features = ["python-extension"], version = "0.19.0" }

examples/python-extension/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Python environment that has torch installed from the root of the github repo.
1111

1212
```bash
1313
LIBTORCH_USE_PYTORCH=1 cargo build -p tch-ext && cp -f target/debug/libtch_ext.so tch_ext.so
14-
python examples/python-extension/main.py
14+
PYTHONPATH=. python examples/python-extension/test.py
1515
```
1616

1717
It is recommended to run the build with `LIBTORCH_USE_PYTORCH` set, this will

examples/python-extension/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn add_one(tensor: PyTensor) -> PyResult<PyTensor> {
1111
/// objects.
1212
#[pymodule]
1313
fn tch_ext(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
14-
py.import_bound("torch")?;
14+
py.import("torch")?;
1515
m.add_function(wrap_pyfunction!(add_one, m)?)?;
1616
Ok(())
1717
}

pyo3-tch/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ license = "MIT/Apache-2.0"
1414
[dependencies]
1515
tch = { path = "..", features = ["python-extension"], version = "0.19.0" }
1616
torch-sys = { path = "../torch-sys", features = ["python-extension"], version = "0.19.0" }
17-
pyo3 = { version = "0.21", features = ["extension-module"] }
17+
pyo3 = { version = "0.24", features = ["extension-module"] }

pyo3-tch/src/lib.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn wrap_tch_err(err: tch::TchError) -> PyErr {
1818
}
1919

2020
impl<'source> FromPyObject<'source> for PyTensor {
21-
fn extract(ob: &'source PyAny) -> PyResult<Self> {
21+
fn extract_bound(ob: &Bound<'source, PyAny>) -> PyResult<Self> {
2222
let ptr = ob.as_ptr() as *mut tch::python::CPyObject;
2323
let tensor = unsafe { tch::Tensor::pyobject_unpack(ptr) };
2424
tensor
@@ -31,13 +31,18 @@ impl<'source> FromPyObject<'source> for PyTensor {
3131
}
3232
}
3333

34-
impl IntoPy<PyObject> for PyTensor {
35-
fn into_py(self, py: Python<'_>) -> PyObject {
34+
impl<'py> IntoPyObject<'py> for PyTensor {
35+
type Output = Bound<'py, Self::Target>;
36+
type Target = PyAny;
37+
type Error = PyErr;
38+
39+
fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> {
3640
// There is no fallible alternative to ToPyObject/IntoPy at the moment so we return
3741
// None on errors. https://github.com/PyO3/pyo3/issues/1813
38-
self.0.pyobject_wrap().map_or_else(
42+
let v = self.0.pyobject_wrap().map_or_else(
3943
|_| py.None(),
4044
|ptr| unsafe { PyObject::from_owned_ptr(py, ptr as *mut pyo3::ffi::PyObject) },
41-
)
45+
);
46+
Ok(v.into_pyobject(py)?)
4247
}
4348
}

0 commit comments

Comments
 (0)