1515//! ```rust
1616//! # use std::panic::{catch_unwind, AssertUnwindSafe};
1717//! #
18- //! use numpy::PyArray1;
18+ //! use numpy::{ PyArray1, PyArrayMethods} ;
1919//! use ndarray::Zip;
20- //! use pyo3::Python;
20+ //! use pyo3::{ Python, Bound} ;
2121//!
22- //! fn add(x: &PyArray1<f64>, y: &PyArray1<f64>, z: &PyArray1<f64>) {
22+ //! fn add(x: &Bound<'_, PyArray1<f64>> , y: &Bound<'_, PyArray1<f64>> , z: &Bound<'_, PyArray1<f64> >) {
2323//! let x1 = x.readonly();
2424//! let y1 = y.readonly();
2525//! let mut z1 = z.readwrite();
4141//! }
4242//!
4343//! Python::with_gil(|py| {
44- //! let x = PyArray1::<f64>::zeros (py, 42, false);
45- //! let y = PyArray1::<f64>::zeros (py, 42, false);
46- //! let z = PyArray1::<f64>::zeros (py, 42, false);
44+ //! let x = PyArray1::<f64>::zeros_bound (py, 42, false);
45+ //! let y = PyArray1::<f64>::zeros_bound (py, 42, false);
46+ //! let z = PyArray1::<f64>::zeros_bound (py, 42, false);
4747//!
4848//! // Will work as the three arrays are distinct.
49- //! add(x, y, z);
49+ //! add(& x, & y, & z);
5050//!
5151//! // Will work as `x1` and `y1` are compatible borrows.
52- //! add(x, x, z);
52+ //! add(& x, & x, & z);
5353//!
5454//! // Will fail at runtime due to conflict between `y1` and `z1`.
5555//! let res = catch_unwind(AssertUnwindSafe(|| {
56- //! add(x, y, y);
56+ //! add(& x, & y, & y);
5757//! }));
5858//! assert!(res.is_err());
5959//! });
9191//! ```rust
9292//! # use std::panic::{catch_unwind, AssertUnwindSafe};
9393//! #
94- //! use numpy::PyArray2;
95- //! use pyo3::{types::IntoPyDict, Python};
94+ //! use numpy::{ PyArray2, PyArrayMethods} ;
95+ //! use pyo3::{types::{ IntoPyDict, PyAnyMethods} , Python};
9696//!
9797//! Python::with_gil(|py| {
98- //! let array = PyArray2::<f64>::zeros (py, (10, 10), false);
99- //! let locals = [("array", array)].into_py_dict (py);
98+ //! let array = PyArray2::<f64>::zeros_bound (py, (10, 10), false);
99+ //! let locals = [("array", array)].into_py_dict_bound (py);
100100//!
101- //! let view1 = py.eval ("array[:, ::3]", None, Some(locals)).unwrap().downcast ::<PyArray2<f64>>().unwrap();
102- //! let view2 = py.eval ("array[:, 1::3]", None, Some(locals)).unwrap().downcast ::<PyArray2<f64>>().unwrap();
101+ //! let view1 = py.eval_bound ("array[:, ::3]", None, Some(& locals)).unwrap().downcast_into ::<PyArray2<f64>>().unwrap();
102+ //! let view2 = py.eval_bound ("array[:, 1::3]", None, Some(& locals)).unwrap().downcast_into ::<PyArray2<f64>>().unwrap();
103103//!
104104//! // A false conflict as the views do not actually share any elements.
105105//! let res = catch_unwind(AssertUnwindSafe(|| {
@@ -628,7 +628,7 @@ mod tests {
628628 #[ test]
629629 fn test_debug_formatting ( ) {
630630 Python :: with_gil ( |py| {
631- let array = PyArray :: < f64 , _ > :: zeros ( py, ( 1 , 2 , 3 ) , false ) ;
631+ let array = PyArray :: < f64 , _ > :: zeros_bound ( py, ( 1 , 2 , 3 ) , false ) ;
632632
633633 {
634634 let shared = array. readonly ( ) ;
@@ -654,7 +654,7 @@ mod tests {
654654 #[ should_panic( expected = "AlreadyBorrowed" ) ]
655655 fn cannot_clone_exclusive_borrow_via_deref ( ) {
656656 Python :: with_gil ( |py| {
657- let array = PyArray :: < f64 , _ > :: zeros ( py, ( 3 , 2 , 1 ) , false ) ;
657+ let array = PyArray :: < f64 , _ > :: zeros_bound ( py, ( 3 , 2 , 1 ) , false ) ;
658658
659659 let exclusive = array. readwrite ( ) ;
660660 let _shared = exclusive. clone ( ) ;
@@ -664,14 +664,14 @@ mod tests {
664664 #[ test]
665665 fn failed_resize_does_not_double_release ( ) {
666666 Python :: with_gil ( |py| {
667- let array = PyArray :: < f64 , _ > :: zeros ( py, 10 , false ) ;
667+ let array = PyArray :: < f64 , _ > :: zeros_bound ( py, 10 , false ) ;
668668
669669 // The view will make the internal reference check of `PyArray_Resize` fail.
670- let locals = [ ( "array" , array) ] . into_py_dict ( py) ;
670+ let locals = [ ( "array" , & array) ] . into_py_dict_bound ( py) ;
671671 let _view = py
672- . eval ( "array[:]" , None , Some ( locals) )
672+ . eval_bound ( "array[:]" , None , Some ( & locals) )
673673 . unwrap ( )
674- . downcast :: < PyArray1 < f64 > > ( )
674+ . downcast_into :: < PyArray1 < f64 > > ( )
675675 . unwrap ( ) ;
676676
677677 let exclusive = array. readwrite ( ) ;
@@ -682,7 +682,7 @@ mod tests {
682682 #[ test]
683683 fn ineffective_resize_does_not_conflict ( ) {
684684 Python :: with_gil ( |py| {
685- let array = PyArray :: < f64 , _ > :: zeros ( py, 10 , false ) ;
685+ let array = PyArray :: < f64 , _ > :: zeros_bound ( py, 10 , false ) ;
686686
687687 let exclusive = array. readwrite ( ) ;
688688 assert ! ( exclusive. resize( 10 ) . is_ok( ) ) ;
0 commit comments